Filters
From Linux Shell Scripting Tutorial - A Beginner's handbook
- If a Linux command accepts its input data from the standard input and produces its output (result) on standard output is known as a filter.
- Filters usually works with Linux pipes.
Syntax
The syntax is:
command1 | command2 command1 file.txt | command2 command1 args < input.txt | command2
Where,
- command2 is a filter command.
Example
In this example, the grep command act as a filter (it will filter out name vivek from its input):
cut -d: -f1 /etc/passwd | sort | uniq | grep vivek
Filter ps command output using the grep command:
ps aux | grep php-cgi
Consider the following example:
sort < sname | uniq > u_sname
The uniq command is filter, which takes its input from the sort command and passes output as input to uniq command; Then uniq command output is redirected to "u_sname" file. The grep command is considered as one of most popular filter under Linux and UNIX like operating systems.
Commonly used filter commands