Tutorial by Examples

cat file.txt will print the contents of a file. If the file contains non-ASCII characters, you can display those characters symbolically with cat -v. This can be quite useful for situations where control characters would otherwise be invisible. cat -v unicode.txt Very often, for interactive ...
Use the --number flag to print line numbers before each line. Alternatively, -n does the same thing. $ cat --number file 1 line 1 2 line 2 3 4 line 4 5 line 5 To skip empty lines when counting lines, use the --number-nonblank, or simply -b. $ cat -b file 1 line 1 2 line ...
cat < file.txt Output is same as cat file.txt, but it reads the contents of the file from standard input instead of directly from the file. printf "first line\nSecond line\n" | cat -n The echo command before | outputs two lines. The cat command acts on the output to add line num...
This is the primary purpose of cat. cat file1 file2 file3 > file_all cat can also be used similarly to concatenate files as part of a pipeline, e.g. cat file1 file2 file3 | grep foo
cat >file It will let you write the text on terminal which will be saved in a file named file. cat >>file will do the same, except it will append the text to the end of the file. N.B: Ctrl+D to end writing text on terminal (Linux) A here document can be used to inline the content...
This is useful to see if there are any non-printable characters, or non-ASCII characters. e.g. If you have copy-pasted the code from web, you may have quotes like ” instead of standard ". $ cat -v file.txt $ cat -vE file.txt # Useful in detecting trailing spaces. e.g. $ echo '” ' | c...
Files compressed by gzip can be directly concatenated into larger gzipped files. cat file1.gz file2.gz file3.gz > combined.gz This is a property of gzip that is less efficient than concatenating the input files and gzipping the result: cat file1 file2 file3 | gzip > combined.gz A compl...

Page 1 of 1