2025-3-29 Linux Literacy CAT

BASED ON Cat

Cat is part of Gnu Coreutils, made to Concatenate and write files.

SETUP

Here is the content of file.txt:

This is a file
	this is a tab


this is some lines

Inputs

There is 2 main way to feed inputs in cat:

File

cat file.txt

-will show the file

Pipe

echo "This is test" | cat

we know (;

Options

Create a file

Will take data from standard input. (CTRL-D to quit)

cat > file2.txt

cat file2.txt

this will show the whole new file

Append a file

cat >> file2.txt

cat file2.txt

New file gets updated

Concatenate

cat file.txt file2.txt > file3.txt

cat file3.txt

we see the 2 content in 1 file

The "-" is standard input, which will allow you to add the data you want. (CTRL-D to quit)

cat file.txt - file2.txt > file3.txt

cat file3.txt

we see the 2 content + added data in 1 file

Tac

cat in reverse, will reed line from bottom up

tac file.txt

Numbered line

cat -n file.txt

Numbered line with content

cat -b file.txt

Squeeze blank

Will squeeze repeated blank line into one.

cat -s file.txt

Highlight end of line

cat -E file.txt

Highlight tab

cat -T file.txt