---

developerWorks: Concatenating Files with cat

“Often you need to process several files as one and save the
results of such processing to a single output file. The cat (short
for ‘concatenate’) command takes one or more files on its input and
prints them to its output as a single file. For example, cat
chapter01 chapter02 chapter03 > book saves three chapterXX files
into a single book file.

“The input files are printed in the order they are listed after
the cat command, so to reverse the order of information, you must
first reverse the order of input files. Also, when the number of
files that need to be processed is too large for you to type their
names by hand, you may use a wildcard, as in cat chapter* > book
remembering that the names of the files will be sorted in ascending
order. This may cause interesting problems when you suddenly find
out that chapter13 is sent to the output before chapter2, while
chapter13 is sent to the output after chapter02.

“When the output of cat is not redirected to a file or another
command’s standard input, cat behaves as most command-line tools
and send its output to the console. This means that you can use cat
to display files; for example, you can use cat /etc/passwd to
display the contents of the system password file. For convenience,
should should view large files with less, as in less /etc/passwd
(you can learn more about less by typing man less)…”


Complete Story

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis