From Linux Bash Shell Scripting Tutorial Wiki
Jump to navigation Jump to search

← Why use pipesHomeChapter 7 Challenges →


The syntax is as follows:

command1 | command2 
command1 file.txt | command2
command1 args < input.txt | command2


  • command2 is a filter command.


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

← Why use pipesHomeChapter 7 Challenges →