cat命令

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
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东城绝神

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值