cat命令
cat语法:cat (选项) 参数
[root@salt-master python]# cat --help
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s), or standard input, to standard output.
-A, --show-all equivalent to -vET
-b, --number-nonblank number nonempty output lines, overrides -n
-e equivalent to -vE
-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 -vT
-T, --show-tabs display TAB characters as ^I
-u (ignored)
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
--help display this help and exit
--version output version information and exit
选项:
-n或-number:有1开始对所有输出的行数编号;
-b或--number-nonblank:和-n相似,只不过对于空白行不编号;
-s或--squeeze-blank:当遇到有连续两行以上的空白行,就代换为一行的空白行;
-A:显示不可打印字符,行尾显示“$”;
-e:等价于"-vE"选项;
-t:等价于"-vT"选项;
常用cat用法:
实例一:打印行号
[root@salt-master python]# cat -n format-01.py
1 #!/usr/bin/pytho
2 # -*- conding:utf-8 -*-
3
4 print ('{:>8}'.format('3.14'))
5 print ('{:<8}'.format('3.14'))
6 print ('{:^8}'.format('3.14'))
7 print ('{:0>8}'.format('3.14'))
8 print ('{:a>8}'.format('3.14'))
实例二:将while-01.py与while-02.py的内容合并到a.txt文件
[root@salt-master python]# cat while-01.py while-02.py > a.txt
[root@salt-master python]# cat a.txt
[root@salt-master python]# cat -n a.txt
1 #!/usr/bin/python
2 # -*- coding:utf-8 -*-
3
4 num=0
5
6 while num < 10:
7 num+=1
8 if num == 7:
9 print 'I am here'
10 else:
11 print num
12 #!/usr/bin/python
13 # -*- coding:utf-8 -*-
14
15 num=0
16
17 while num < 10:
18 num+=1
19 if num == 7:
20 continue
21 print num
实例三:
[root@salt-master python]# cat << eof >> b.txt
zhangyike
zhangjunchao
eof
[root@salt-master python]# cat b.txt
zhangyike
zhangjunchao
实例四:让b.txt文件的内容纵列整齐排序
[root@iZwz9bhan5nqzh979qokrkZ ~]# cat b.txt | column -t
zhangjunchao fdsf
fkdsalf fdfdfdfd
fdsafjsafs 4324234
12341231244 4343
3213123 67745
6746 ggf
gf klll
sdfsdf ggd
s