Cat output file contents:
Command description: Cat (concatenate abbreviation), a Linux built-in command to connect one or more files together, and standard output or input. Often used to display the contents of a file, or to connect several files to display, or to read from standard input and display. It is often used in conjunction with redirection symbols.
Command function:
a) Show entire file at once: Catfilename
b) Create a file from the keyboard:cat> filename can only create new files and cannot edit existing files
c) merge several files into one file: catfile1 file2 > file
Note: Cat file1 file2 > file file1, File2 will overwrite the original content in file;
cat file1 file2 >> file File1 , the file2 is appended to the file's original content.
Command format:
[Email protected] ~]#cat [ options] [file]
Command parameters:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/75/A2/wKioL1Y_bE2iBZWKAAB8Shd-BoM121.jpg "title=" can parameters. jpg "alt=" wkiol1y_be2ibzwkaab8shd-bom121.jpg "/>
Command instance:
Example 1: Displaying file contents
[email protected] test]# cat A.txt
2
3
Qw
Sd
D
Example 2: Displaying the contents of a file and adding a line number
[Email protected] test]# cat-n a.txt
1 2
2
3
4 3
5 QW
6 SD
7 D
Example 3: Display the contents of a file and add line numbers to ignore empty lines
[Email protected] test]# Cat-b a.txt
1 2
2 3
3 QW
4 SD
5 D
Example 4: Displays the contents of a file, and when it encounters a blank line with more than two consecutive lines, it is substituted with a blank line of one line
[Email protected] test]# cat-s a.txt
2
3
Qw
Sd
D
Expand:
Example 5: Add a line number to the B.txt file and enter it into the A.txt file .
[email protected] test]# cat B.txt
Hello Linux
[email protected] test]# cat A.txt
Qwe
Asdf
Zxc
[Email protected] test]# cat-n b.txt a.txt
1 Hello Linux
2 Qwe
3 ASDF
4 ZXC
Example 6: Add the B.txt and C.txt file contents to the line number (blank line not added) after input into the a.txt file
[email protected] test]# cat B.txt
Hello Linux
[email protected] test]# cat C.txt
ln
Linux
[email protected] test]# cat A.txt
Qwe
Asdf
Zxc
[Email protected] test]# cat-b b.txt c.txt a.txt
1 Hello Linux
2 LN
3 Linux
4 Qwe
5 ASDF
6 ZXC
Example 7: Using here doc to generate files
[email protected] test]# cat >a.txt <<eof
> Lnlinux
> Hello
> EOF
[Email protected] test]# ls-l a.txt
-rw-r--r--1 root root 7 11:41 a.txt
[email protected] test]# cat A.txt
Lnlinux
Hello
Description: Here doc can be used for string substitution.
Reverse list: TAC
[Email protected] test]# TAC A.txt
Hello
Lnlinux
Description: TAC is writing cat back, so his function is in contrast to cat, where cat is continuously displayed on the screen from the first line to the last row, while the TAC is displayed on the screen in reverse from the last line to the first line!
This article is from the "Lnlinux" blog, make sure to keep this source http://lnlinux.blog.51cto.com/1331535/1710858
Linux Common Basic Command cat detailed description