Professional Documents
Culture Documents
Filters
Filters
Head
The tail command in unix or linux system is used to print the last
N lines from the file to the terminal.
By default, the head command prints the last10 lines from a file.
tail example.txt
Use the -n option to print the last n lines from a file. The following
example prints the last 2 lines from the file:
tail –n 2 example.txt
Cut
Cut command is used to select sections of text from each line of
files.
cut command is used to select fields or columns from a line by
specifying a delimiter or by specifying the range or characters.
The cut command can be used to print characters in a line by
specifying the position of the characters. To print the characters
in a line, use the -c option in cut command
cut –c 4 file.txt
The above cut command prints the fourth character in each line
of the file.
cut –c 4,6 file.txt
The above cut command prints the fourth and sixth character in
each line of the file.
cut -c4-7 file.txt
The above cut command prints the characters from fourth
position to the seventh position in each line.
Cut
cut –c -6 file.txt
This is used to print the first six characters in a line, from the start
position.
To print the characters from tenth position to the end, specify
only the start position and omit the end position.
cut –c 10- file.txt
cut command is used to extract the fields in a file using a
delimiter. The -d option in cut command can be used to specify
the delimiter and -f option is used to specify the field position.
cut –d ' ' –f 2 file.txt
print a range of fields by specifying the start and end position.
cut –d ' ' –f 1-3 file.txt
Paste
The paste command merges the lines from multiple files. The
paste command sequentially writes the corresponding lines from
each file separated by a TAB delimiter on the unix terminal.
paste file1 file2
the paste command merges the files in parallel.
change the delimiter to any other character by using the -d option
paste –d "|" file1 file2
Sort command