Shell Data Processing - Cat command (short for concatenate)

About

cat 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:

Example:

  • As a prerequisite, we create two files f and g that contains the text Hello World with the help of tee that redirect the output of the echo command to this files.
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
cat < helloIn.txt > helloOut.txt
  • Result: showing the content of helloOut.txt with cat
cat helloOut.txt
Hello World

Powered by ComboStrap