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. You can use them on the command line and in shell script files. Also, then... you may not need to write as many Perl (Python/Tcl/etc.) scripts!
< previous  index  next >

Contact Jerry Peek