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

来源:互联网 发布:淘宝食品店需要什么 编辑:程序博客网 时间:2024/05/21 17:29

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/falsenii:x:1000:1000:wzj,,,:/home/nii:/bin/bashsshd:x:120:65534::/var/run/sshd:/usr/sbin/nologinmysql:x:121:132:MySQL Server,,,:/nonexistent:/bin/falsex2gouser:x:122:133::/var/lib/x2go:/bin/falsegdm:x:123:134:Gnome Display Manager:/var/lib/gdm:/bin/falsedebian-spamd:x:124:135::/var/lib/spamassassin:/bin/shftp:x:125:137:ftp daemon,,,:/srv/ftp:/bin/falsestatd:x:126:65534::/var/lib/nfs:/bin/false

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

nii@mch:~/code$ cut -b 1-8 test.c lightdm:nii:x:10sshd:x:1mysql:x:x2gousergdm:x:12debian-sftp:x:12statd:x:

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

nii@mch:~/code$ cut -b 1,8 test.c l:n0s1m:xrg2dsf2s:

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

nii@mch:~/code$ cut -d : -f1 test.c lightdmniisshdmysqlx2gousergdmdebian-spamdftpstatd

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

nii@mch:~/code$ cut -d : -f1,3 test.c lightdm:119nii:1000sshd:120mysql:121x2gouser:122gdm:123debian-spamd:124ftp:125statd:126
0 0
原创粉丝点击