Pipes

Pipes in Unix and MS-DOS/Windows are used for connecting different processes together so that the output of one process becomes the input of the next process. Consider the following set of commands, which would almost work in Unix (if you change the dir to ls) or MS-DOS:

dir > outfile
sort outfile > newfile
more newfile

The output of dir is collected in outfile. Then sort is used to sort outfile, and the output from sort is stored in newfile. Then more shows the contents of newfile a screenful at a time.

Pipes allow you to perform that same sequence, but without outfile and newfile, like this:

dir | sort | more

The output of dir is given to sort, which then sorts the data. The output from sort is then given to more for page-at-a-time ...

Get SAMS Teach Yourself Perl in 24 Hours THIRD EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.