About
cat is a core utility that generates a stream of data from one or more files
It therefore concatenate files.
Example
Concatenate files
file 1 - line 1
file 1 - line 2
file 2 - line 1
file 2 - line 2
- Output file1.txt then file2.txt contents and redirect and create the file fileAll.txt
cat file1.txt file2.txt > fileAll.txt
- Content of fileAll.txt
cat fileAll.txt
file 1 - line 1
file 1 - line 2
file 2 - line 1
file 2 - line 2
Concatenate Output files selected with a glob pattern
Output all files with the pgn extension
cat *.pgn
where: *.pgn is a glob pattern
Concatenate Output files and standard input
Concatenate the output of file and of standard input
cat f - g
where:
- f is a file
- - is standard input
- g is a file
Example:
echo 'Hello World' | tee f g
Copy standard input to standard output
Without any argument, cat will copy standard input to standard output
cat
Example:
- As prerequisites, we create of a input file
echo 'Hello World' > helloIn.txt
- We use then the redirection operator:
- < to set helloIn.txt as the standard input of cat
- > to redirect the standard output into the file helloOut.txt
cat < helloIn.txt > helloOut.txt
- Result: showing the content of helloOut.txt with cat
cat helloOut.txt
Hello World