Simple Filters
Filters are commands which accept data from standard input, manupulate it
and write the results to standard output.
●Head displays the lines at the top of the file
when used without any option it will display first 10 lines of the file
usage: head filename
n > print the first N lines instead of the first 10
●tail displays the lines at the end of the file. By default it will display last 10
lines of the file
usage: tail filename
eg: cut c 1,35 /etc/passwd
● With f option you can cut the feilds delemited by some character
eg: cut d’:’ f2 /etc/passwd
d option is used to specify the delimiter and f option used to specify the
feild number
● paste command will paste the contents of the file side by side
eg: paste a.txt b.txt
whitespaces first, then numerals, uppercase and finally lowercase
you can sort the file based on a field by using t and k option.
Eg: sort t" " k 2 students.txt
sorts the file based on the second field using the delimiter as space
r > reverses the result
and write the results to standard output.
●Head displays the lines at the top of the file
when used without any option it will display first 10 lines of the file
usage: head filename
n > print the first N lines instead of the first 10
●tail displays the lines at the end of the file. By default it will display last 10
lines of the file
usage: tail filename
cut & paste
● cut command can be used to cut the columns from a file with c option.eg: cut c 1,35 /etc/passwd
● With f option you can cut the feilds delemited by some character
eg: cut d’:’ f2 /etc/passwd
d option is used to specify the delimiter and f option used to specify the
feild number
● paste command will paste the contents of the file side by side
eg: paste a.txt b.txt
Ordering a file
●sort reorders lines in the filewhitespaces first, then numerals, uppercase and finally lowercase
you can sort the file based on a field by using t and k option.
Eg: sort t" " k 2 students.txt
sorts the file based on the second field using the delimiter as space
r > reverses the result
Comments
Post a Comment