Pipe command redirects the output of one command to input to another command. That means helpful when we want output of one command to input put to the another command. Pipe command represent symbol as |.
For Example, a file contains list of 1 to 1000 numbers, lets use cat command to display name. But problem with cat command is displays all the output at a time in terminal. We have command called “less” , with this command we can navigate the text in terminal. Lets combine both commands using the Pipe command.
$ cat numbers.txt | less
Some times , when Pipe command can not provide exact input another command , in those case we have to use the “xargs” command. Lets use cat and cal commnad for this use case.
For Example, when use “cal 2018” command it display the complete year’s calendar. for this use case we will take year from the file, let year stored in date.txt file. If use directly will display only current month calendar but this exact output.
When we use the Pipe command with out xargs.
$ cat date.txt | cal
Pipe command with xargs command
$ cat date.txt | xargs cal
By concluding, Pipe command very powerful and useful command in redirecting the output. Happy Learning :).