Commands revisited: pipes and redirection

Joining files together

You can use the cat command to join files together without using an editor. To do this, type cat, the names of the files you want to join together, and then redirect the output into a new file. For example, if you want to join together report1, report2, and report3 into a file called allreps, you could type:

cat report1 report2 report3 > allreps

cat opens a file called allreps and then writes each file, in order, into it. report1 comes first in allreps, followed by report2 and then report3.

Be careful with cat, because you can unintentionally overwrite a file. For example, type:

cat report1 report2 report3 > report1

cat first opens a file called report1, where it writes its input files. This overwrites the existing report1. When cat goes to write its arguments into the file report1 that it has just opened, it finds report1 appears as input as well as output and gives you the error message:

   cat: input/output files 'report1' identical
However, by now it is too late; the contents of report1 have been overwritten.

Next topic: Background processing
Previous topic: Using a file as input to a command

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003