Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)
cat(1) OSS Shell and Utilities Reference Manual
You may want to suppress this message with the -s flag when you use the cat
command in shell procedures.
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 section1. 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 section4.
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−68 Hewlett-Packard Company 527188-021