Member-only story

Text processing from the command line

Rabin Poudyal
3 min readMar 29, 2020

( List of commands that can make you productive in pre-processing text file.)

Every time you want to manipulate your text file, you don’t need to spin up a programming language. The common use cases are while reading a log file directly from a file or input stream; you might want to filter the results, sort them, replace words or whatever your use case be there are few commands that will definitely help you in long run.

Let’s take a look at some of my favorite ones.

Cat:

Reading the whole files into the shell. Cat can work with single or multiple files.

cat file1.txt file2.txt

Head and Tail:

Get data from the top or bottom of your file or input stream.

head -n 5 logs.log
tail -n 6 logs.log
tail -f logs.log // -f means follow; while streaming see what is being written; used for reading logs

Word Count:

Count words, lines or characters with “wc” command.

wc -l file.log // Use -c & -w for characters and words -l means line

Exercise:

Verify that “tail” command prints exactly 10 lines using “wc” command:

tail logs.log | wc -l

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Rabin Poudyal
Rabin Poudyal

Written by Rabin Poudyal

Software Engineer, Data Science Practitioner. Say "Hi!" via email: rabinpoudyal1995@gmail.com or visit my website https://rabinpoudyal.com.np

No responses yet

Write a response