Category

Linux Command


Usage

cat [OPTION]... [FILE]...


Manual

Concatenate FILE(s), or standard input, to standard output. With no FILE, or when FILE is -, read standard input.

Options

  • -A, --show-all: equivalent to simultaneously specify -v, -E, and -T.
  • -b, --number-nonblank: number nonempty output lines
  • -e: equivalent to -v -E
  • -E, --show-ends: display $ at end of each line
  • -n, --number: number all output lines
  • -s, --squeeze-blank: suppress repeated empty output lines
  • -t: equivalent to -v -T
  • -T, --show-tabs: display TAB characters as ^I
  • -u: (ignored)
  • -v, --show-nonprinting: use ^ and M- notation, except for LineFeed (LF, or \n) and TAB
  • --help: display this help and exit
  • --version: output version information and exit

Examples

Displaying file contents

The following command will display the contents of the file.bed on the terminal.

$ cat file.bed | head

chr1    104896    105048    EH38E2776520
chr1    138866    139134    EH38E2776521
chr1    180743    180904    EH38E2776522
chr1    181014    181237    EH38E2776523
chr1    181289    181639    EH38E2776524
chr1    267925    268171    EH38E2776528
chr1    271226    271468    EH38E2776529
chr1    274329    274481    EH38E2776530
chr1    586036    586264    EH38E2776532
chr1    605330    605668    EH38E2776534
Concatenating multiple files

The following command will concatenate the contents of file1.txt and file2.txt into a single file named combined.txt.

$ cat file1.txt file2.txt > combined.txt
Appending to a file

The following command will append the contents of new_content.txt to the end of existing_file.txt.

$ cat new_content.txt >> existing_file.txt
Numbering lines

The following command will display the contents of file.bed, with line numbers added to each line.

$ cat -n file.bed

     1    chr1    104896    105048    EH38E2776520
     2    chr1    138866    139134    EH38E2776521
     3    chr1    180743    180904    EH38E2776522
     4    chr1    181014    181237    EH38E2776523
     5    chr1    181289    181639    EH38E2776524
     6    chr1    267925    268171    EH38E2776528
     7    chr1    271226    271468    EH38E2776529
     8    chr1    274329    274481    EH38E2776530
     9    chr1    586036    586264    EH38E2776532
    10    chr1    605330    605668    EH38E2776534
Displaying non-printing characters

The following command will display the contents of file.bed, showing non-printing characters in a visible format. This functionality can be helpful in inspecting file formats, for example, fields in the bed format are separated by TABs, but sometimes they may mistakenly be separated by spaces. To check if fields are separated by the correct delimiters (TABs will show up as ^I).

$ cat -A file.bed

chr1^I104896^I105048^IEH38E2776520$
chr1^I138866^I139134^IEH38E2776521$
chr1^I180743^I180904^IEH38E2776522$
chr1^I181014^I181237^IEH38E2776523$
chr1^I181289^I181639^IEH38E2776524$


Share your experience or ask a question