5th (Filter)
5th (Filter)
Filters are programs that take plain text(either stored in a file or produced by another program) as
standard input, transforms it into a meaningful format, and then returns it as standard output. Linux has a
number of filters. Some of the most commonly used filters are explained below:
2. head : Displays the first n lines of the specified text files. If the number of lines is not specified then by
default prints first 10 lines.
Syntax:
Syntax:
4. sort : Sorts the lines alphabetically by default but there are many options available to modify the
sorting mechanism. Be sure to check out the main page to see everything it can do.
Syntax:
Syntax:
Syntax:
wc [-options] [path]
Syntax:
8. tac : tac is just the reverse of cat and it works the same way, i.e., instead of printing from lines 1
through n, it prints lines n through 1. It is just reverse of cat command.
Syntax:
tac [path]
9. sed : sed stands for stream editor. It allows us to apply search and replace operation on our data
effectively. sed is quite an advanced filter and all its options can be seen on its man page.
Syntax:
sed [path]
The expression we have used above is very basic and is of the form ‘s/search/replace/g’
Syntax:
nl [-options] [path]