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

without xargs  command

Pipe command with xargs command

$ cat date.txt | xargs cal

With xargs command

By concluding, Pipe command very powerful and useful command in redirecting the output. Happy Learning :).

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: