Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)

cat(1) OSS Shell and Utilities Reference Manual
4. To append one le to the end of another, enter:
cat section1.4 >> section1
The >> in this command species that a copy of section1.4 be added to the end of sec-
tion1. If you want to replace the le, use a single > symbol.
5. To add text to the end of a le, 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 nished.
6. To concatenate several les 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 le
section3.
7. To concatenate several les 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 le 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 > le1
If standard input is a regular le, however, the preceding command is equivalent to the
following:
cat start - middle /dev/null end > le1
The commands are equivalent because the entire contents of the le would be consumed
by cat the rst time - (dash) was used as a le 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 les using the > (redirection symbol). If you do this,
you lose the original data in the input le because the shell truncates it before cat can read it.
(See also the sh command.)
RELATED INFORMATION
Commands: more(1), pr(1), sh(1).
236 Hewlett-Packard Company 527188-003