美文网首页linux 学习
文件处理工具

文件处理工具

作者: 极地冰凌_25bf | 来源:发表于2019-01-30 11:42 被阅读0次

    wc命令:word count(单词统计命令)

    synopsis

    wc [option]....[FILE]
    

    options

    • -l: 只显示行数

          [root@localhost qibin]# wc -l /etc/fstab 
          15 /etc/fstab
      
    • -w: 只显示单词数

          [root@localhost qibin]# wc -c /etc/fstab
          805 /etc/fstab
      

    cut命令:切割文本文件(以指定的字符进行分割)

    synopsis

    cut [option]....[FILE]
    

    options

    • -d DELIMITER: 指名分割符

    • -f FILEDS: 知名要显示的字段

          [root@localhost qibin]# cat /etc/passwd | cut -d : -f 1,2,3,4,5
          root:x:0:0:root
          bin:x:1:1:bin
          daemon:x:2:2:daemon
          adm:x:3:4:adm
          lp:x:4:7:lp
          sync:x:5:0:sync
      
      FILEDS 可以是不连续的如1,3,4 也可以是连续的例如1-3,7
      
    • --output-delimiter=String: 指名输出的分割符

          [root@localhost qibin]# cat /etc/passwd | cut -d : --output-delimiter="    " -f 1,2,3,4,5
          root    x    0    0    root
          bin    x    1    1    bin
          daemon    x    2    2    daemon
          adm    x    3    4    adm
          lp    x    4    7    lp
          sync    x    5    0    sync
      

    sort命令:排序命令

    synopsis

    sort [option]...[FILE]....
    

    options

    • -f: 忽略字符大小写

    • -r: 逆序排列

    • -t DELIMITER: 字段分割符

    • -k #: 以指定字段进行排序

      [root@localhost qibin]# cat /etc/passwd | sort -t : -k 2
      root:x:0:0:root:/root:/bin/bash
      uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
      operator:x:11:0:operator:/root:/sbin/nologin
      usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
      bin:x:1:1:bin:/bin:/sbin/nologin
      games:x:12:100:games:/usr/games:/sbin/nologin
      gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
      
    • -u :去重显示

    uniq命令:去重显示(连续且相同才叫重复)

    synopsis

    uniq [option]...[FILE]...
    

    options

    • -c: 显示每行重复出现的次数

      [root@localhost qibin]# history | cut -d" " -f 5 | sort | uniq -c
      12 cat  
      5 clear  
      16 history  
      2 ifconfig  
      6 ls  
      4 man  
      1 rm  
      1 sort  
      1 sout  
      2 tail  
      1 tty  
      1 uniq  
      1 unique  
      3 vim  
      5 wc  
      2 who  
      1 whoami  
      
    • -d: 仅显示重复过的行

      [root@localhost qibin]# history | cut -d" " -f 5 | sort | uniq -d
      cat
      clear
      history
      ifconfig
      ls
      man
      tail
      vim
      wc
      who
      
    • -u: 仅显示不曾出现过的行

      [root@localhost qibin]# history | cut -d" " -f 5 | sort | uniq -u
      1  
      2  
      3  
      4  
      5  
      6  
      7  
      8  
      9  
      rm  
      sort  
      sout  
      tty  
      uniq  
      unique  
      whoami  
      

    相关文章

      网友评论

        本文标题:文件处理工具

        本文链接:https://www.haomeiwen.com/subject/ruiqsqtx.html