Concatenating with cat
The cat
command displays or concatenates the contents of a file, but cat
is capable of more. For example, cat
can combine standard input data with data from a file. One way of combining the stdin
data with file data is to redirect stdin
to a file and then append two files. The cat
command can do this in a single invocation. The next recipes show basic and advanced usages of cat
.
How to do it...
The cat
command is a simple and frequently used command and it stands for conCATenate.
The general syntax of cat
for reading contents is as follows:
$ cat file1 file2 file3 ...
This command concatenates data from the files specified as command-line arguments and sends that data to stdout
.
- To print contents of a single file, execute the following command:
$ cat file.txt This is a line inside file.txt This is the second line inside file.txt
- To print contents of more than one file, execute the following command:
$ cat one.txt two.txt This line is from one.txt ...