cat – concatenate command

NAME
cat – concatenate files and print on the standard output

SYNOPSIS
cat [OPTION]… [FILE]…

Here Document: the here document syntax can be used with the cat command:

cat > readme.txt << EOF
This is an input stream literal
EOF

where EOF is a token that tells the cat command to terminate when it sees such a token in the subsequent lines.

The token can be any other value as long as it is distinct enough that it won’t appear in the input stream literal. Note that both of the starting and ending EOF tokens will not show up in the readme.txt file.

Examples:

Display a file:
cat myfile.txt

Display all .txt files:
cat *.txt

Concatenate (combine) two files:
cat File1.txt File2.txt > union.txt

If you need to combine two files but also eliminate duplicates (deduplication), this can be done with sort unique:
sort -u File1.txt File2.txt > unique_union.txt

Put the contents of a file into a variable
my_variable='cat File3.txt'

Link:
https://www.baeldung.com/linux/cat-writing-file

https://ss64.com/osx/cat.html

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *