Linux命令: cut命令的使用方法

1、cut用法(文本显示剪切)


   -d : 制定字段分隔符,默认是空格 
   -f :制定要显示的字段 
         -f1 :显示第一个字段 
         -f 1,3 显示第一个和第三个 
         -f 1-3 显示第一个到第三个 
   -b : 显示字节数 
   -c : 显示字符


2、示例

现在有一个test.c文件如下:

nii@mch:~/code$ cat test.c 
lightdm:x:119:129:Light Display Manager:/var/lib/lightdm:/bin/false
nii:x:1000:1000:wzj,,,:/home/nii:/bin/bash
sshd:x:120:65534::/var/run/sshd:/usr/sbin/nologin
mysql:x:121:132:MySQL Server,,,:/nonexistent:/bin/false
x2gouser:x:122:133::/var/lib/x2go:/bin/false
gdm:x:123:134:Gnome Display Manager:/var/lib/gdm:/bin/false
debian-spamd:x:124:135::/var/lib/spamassassin:/bin/sh
ftp:x:125:137:ftp daemon,,,:/srv/ftp:/bin/false
statd:x:126:65534::/var/lib/nfs:/bin/false

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

cut -b 1-8 test.c //显示文件的第一个到第八个字节

nii@mch:~/code$ cut -b 1-8 test.c 
lightdm:
nii:x:10
sshd:x:1
mysql:x:
x2gouser
gdm:x:12
debian-s
ftp:x:12
statd:x:
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

cut -b 1,8 test.c //显示文件的第一个和第八个字节

nii@mch:~/code$ cut -b 1,8 test.c 
l:
n0
s1
m:
xr
g2
ds
f2
s:

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

cut -d : -f1 test.c //:为分割符,显示分割之后的第一个区域

nii@mch:~/code$ cut -d : -f1 test.c 
lightdm
nii
sshd
mysql
x2gouser
gdm
debian-spamd
ftp
statd
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

cut -d : -f1,3 test.c //:为分割符,显示分割之后的第一个和第三个区域

nii@mch:~/code$ cut -d : -f1,3 test.c 
lightdm:119
nii:1000
sshd:120
mysql:121
x2gouser:122
gdm:123
debian-spamd:124
ftp:125
statd:126
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值