Text file manipulation commands
Cat
First command is cat. cat writes the contents of a file to the screen.
machine@machine:~ cat exemplo
Red
yellow
brown
black
white
purple
blue
On the cat, we have the -b option that numbers the lines that are not blank.
machine@machine:~ cat exemplo -b
1 Red
2 yellow
3 brown
4 black
5 white
6 purple
7 blue
Main flags of cat:
-
-bnumbers all non-blank lines. -
-nnumbers all lines, even blank ones. -
-ashow special characters and tabs.
Another cat-like command is tac. They read the contents of a file backwards.
machine@machine:~ tac exemplo
blue
purple
white
black
brown
yellow
Red
Tail
tail shows the last lines of a file.
tail <file.txt>
flags:
-
-n5show the last 5 lines of the file -
-n10lasts ten lines.
In this flag above you can define the number of lines you would like to see, just change it.
Head
The head command displays the first 5 lines of a file.
flags:
-
-n5show the first 5 lines of the file -
-n10First ten lines. -
-c10Displays the first ten characters of the file
Wc
wc counts the number of characters, words, lines and bytes in a file.
wc <file.txt>
flags:
-
-lspecifies number of lines -
-wspecifies number of words -
-mspecifies number of characters -
-cspecifies number of bytes
Sort
The use of sort is to sort the contents of a file.
sort <file.txt>
With the -r option, reverse order is also possible.
Uniq
uniq writes to output without repeating words from a file
-
-ushow lines that have not been repeated -
-dshow lines that have been repeated -
-ccounts the number of repeated lines
OBS: To be able to use uniq it must be used together with sort before being able to sort the file's contents.
___________<< back______________next page >>__________

Top comments (0)