Open System Services Shell and Utilities Reference Manual (G06.27+, H06.04+)
cat(1) OSS Shell and Utilities Reference Manual
4. To append one file to the end of another, enter:
cat section1.4 >> section1
The >> in this command specifies that a copy of section1.4 be added to the end of sec-
tion1. If you want to replace the file, use a single > symbol.
5. To add text to the end of a file, enter:
cat >> notes
Get milk on the way home
<Ctrl-y>
Get milk on the way home is added to the end of notes. When you use this syntax, the
cat command waits for you to enter text. Press the End-of-File key sequence (<Ctrl-y>
above) to indicate you are finished.
6. To concatenate several files with text entered from the keyboard, enter:
cat section3.1 - section3.3 > section3
This concatenates section3.1, text from the keyboard, and section3.3 to create the file
section3.
7. To concatenate several files with output from another command, enter:
ls | cat section4.1 - > section4
This command copies section4.1 and then the output of the ls command to the file sec-
tion4.
8. To get two pieces of input from the terminal (when standard input is a terminal) with a
single command invocation, enter:
cat start - middle - end > file1
If standard input is a regular file, however, the preceding command is equivalent to the
following:
cat start - middle /dev/null end > file1
The commands are equivalent because the entire contents of the file would be consumed
by cat the first time - (dash) was used as a file argument. An End-of-File condition
would then be detected immediately when - appeared the second time.
CAUTIONS
Do not redirect output to one of the input files using the > (redirection symbol). If you do this,
you lose the original data in the input file because the shell truncates it before cat can read it.
(See also the sh command.)
RELATED INFORMATION
Commands: more(1), pr(1), sh(1).
2−36 Hewlett-Packard Company 527188-004