Redirection



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

Redirection

To redirect input for a Unix command from a file instead of the terminal, enter the command as:  

% command < infile Take input from file infile.
% command arguments < infile Take input from file infile.

Here infile is the file from which the command gets its input, and the command's options and arguments are placed before redirection.

To redirect output generated by a Unix command to a file rather than the terminal, enter the command as:

% command > outfile Place output in file outfile.
% command arguments > outfile Place output in file outfile.

Here outfile is the file to which the command sends its output.

Consider the grep command. It is used to search a file for a string and write all lines that contain that string to the standard output device. For example,

% grep FORMAT *.f Search all .f files for word FORMAT.

will search all files with the suffix .f for the character string (word) FORMAT and will fill up your terminal screen in a flash with the file names and lines containing FORMAT. Or, you can place the screenfuls of output in the file matches with redirection

% grep FORMAT *.f >matches Search, puts finds in matches.



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