O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.8. Combining standard output and error

A neat way of quickly identifying errors is first to direct the output to a file, then direct the errors to another file. Here’s an example.

I have two account files, one that contains information, another that does not (but I do not know this). I want to redirect both files to an output file called accounts.out.

						$ cat account_qtr.doc account_end.doc 1> accounts.out 2> accounts.err
					

Now if I have errors, it will be contained in the file accounts.err.

						$ pg accounts.out 
AVBD 34HJ   OUT 
AVFJ   31KO  OUT 
... 

$ pg accounts.err 
cat: account_end.doc: No such file or directory
					

Without previously knowing if the second file ‘ account_end.doc ’ contained information, using the above redirection for output and errors ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required