Next: Simple Scanning - Up: Introduction Previous: Introduction

Introduction to Unix Pipes and redirection

Unix experts can skip this section!

SCANPS and associated programs make use of Unix standard input and output to simplify data processing. This brief introduction should help those who are either novices at Unix, or have never made use of pipes (|) and redirection (< >).

Unix programs read instructions from standard input (stdin) and write output to standard output (stdout). By default, standard input is the keyboard and standard output is the screen. A feature of Unix is that you can redirect the input to come from a file by appending the '<' character, and redirect output by appending the '>' character.

For example: let us suppose we have a program called ``garbage'' which we would like to have read data from a file called ``in.dat'' and write the results to a file called ``out.dat''. We could type:



garbage < in.dat > out.dat

Unix also includes the pipe character '|'. This allows the output of one program to be directed to the input of another. For example, suppose we want to process the output of the ``garbage'' program using another program called ``cleaner'', then one way to do this would be to type:



garbage < in.dat > out.dat

cleaner < out.dat > cleaned.dat

This saves the results of the ``garbage'' program in the file out.dat, then takes the out.dat file as input to the ``cleaner'' program, finally saving the results to the file cleaned.out.

A neater solution using a pipe does away with the need for the out.dat file altogether:



garbage < in.dat | cleaner > cleaned.out


gjb@bioch.ox.ac.uk