UNIX Filters and Pipes

  • Filters: UNIX "building block" utilities designed to work with each other
  • A filter reads a file, else its standard input (stdin); writes to its standard output (stdout)
  • A pipe (written |) connects stdout of one process to stdin of another process.
    • Example: grep reads files and writes matching lines to its stdout; lpr reads its stdin, then prints it:
      % grep something file* | lpr
    • Example: Same as above, but pr paginates output of grep and adds page headers and numbers, passes its results to lpr:
      % grep something file* | pr | lpr
  • Learn the UNIX utilities; maybe you don't need to write as many Perl scripts!
< previous  index  next >

Contact Jerry Peek