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 ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.