Combining I/O Redirection and Piping



next up previous contents index
Next: Redirecting Error Messages Up: Redirecting I/O and Previous: Piping

Combining I/O Redirection and Piping

Combining piping, I/O redirection, and program execution provides a general technique for performing complex operations by putting together simple commands. Since programming languages run under Unix, your home-grown program which reads and writes to your terminal can easily be converted to one which reads and writes to files instead (this is how serious computational scientists do it).  

Suppose you are fed up and wish to change myprog from prompting you for input from your terminal to reading its input from a file infile. You do this with:

% myprog < infile Execute myprog, input file infile.

If you want to examine the output from myprog in a civilized manner via more, you would combine these tricks,

% myprog < infile | more Input from infile, output to more.

If you still find you're wading through too much output, you can have Unix search through your program's output for, say, the specific string uninitialized with:

% myprog < input-file | grep uninitialized | more



next up previous contents index
Next: Redirecting Error Messages Up: Redirecting I/O and Previous: Piping