Manipulating Linux command line output

The following are ways to manipulate the screen/standard output of any Linux command,
Piping the output to another command using |
Redirecting output via >
Redirecting output via >> (to append)
Redirecting only errors via 2>
Redirecting standard input via <
Use tee option with | (pipe) to copy input to standard output (terminal) and more than one output files. e.g. cat original | tee copy1 copy2

Use tee –a to append to files. e.g. cat file.txt | tee -a file_all.txt
Grep: It scans output line per line, searching for matching patterns.
All lines containing the pattern will be printed to standard output. e.g. cat countriesandcapitals.txt | grep Nigeria
This can be reversed using the –v option.
 Sort: It allows you to sort the output lines before displaying.
Default is in alphabetical order. e.g. cat alphabets | sort
It can also sort by file size, when sorting ls output. e.g. ls ~/ -la | sort -nk 5
And when used with uniq, it can sort and filter out double entries. e.g. sort itemlist | uniq

0 comments:

Post a Comment

 
Follow me on Twitter | About me | Terms of Service | Privacy Policy