zoukankan      html  css  js  c++  java
  • uniq命令详解

      

    基础命令学习目录首页

    原文链接:http://man.linuxde.net/uniq

    删除重复行:

    uniq file.txt
    sort file.txt | uniq
    sort -u file.txt
    

    只显示单一行:

    uniq -u file.txt
    sort file.txt | uniq -u

    统计各行在文件中出现的次数:

    sort file.txt | uniq -c

    在文件中找出重复的行:

    sort file.txt | uniq -d

    原文链接:https://www.cnblogs.com/f-ck-need-u/p/7454597.html

    uniq是去重,不相邻的行不算重复值。

    uniq [OPTION]... [INPUT [OUTPUT]]

    选项说明:

    -c:统计出现的次数(count)。

    -d:只显示被计算为重复的

    -D:显示所有被计算为重复的

    -u:显示唯一值,即没有重复值的

    -i:忽略大小写。

    -z:在末尾使用,而不是换行符。

    -f:跳过多少个字段(field)开始比较重复值。

    -s:跳过多少个字符开始比较重复值。

    -w:比较重复值时每行比较的最大长度。即对每行多长的字符进行比较。

    示例:

    [root@xuexi tmp]# cat uniq.txt
    111
    223
    56
    111
    111
    567
    223

    下面的命令删除了相邻的重复行,但是第一行111没有删除。

    [root@xuexi tmp]# uniq uniq.txt
    111
    223
    56
    111   # 删除了重复的111
    567
    223

    排序后去重。

    [root@xuexi tmp]# sort uniq.txt | uniq
    111
    223
    56
    567

    使用-d显示重复的行。

    [root@xuexi tmp]# sort uniq.txt | uniq  -d
    111
    223

    使用-D显示所有重复过的行。

    [root@xuexi tmp]# sort uniq.txt | uniq  -D
    111
    111
    111
    223
    223

    使用-u显示唯一行。

    [root@xuexi tmp]# sort uniq.txt | uniq  -u
    56
    567

    使用-c统计哪些记录出现的次数。

    [root@xuexi tmp]# sort uniq.txt | uniq  -c  
          3 111
          2 223
          1 56
          1 567

    使用-d -c统计重复行出现的次数。

    [root@xuexi tmp]# sort uniq.txt | uniq  -d -c
          3 111
          2 223

    -c不能和-D一起使用。结果说显示所有重复行再统计重复次数是毫无意义的行为。

    [root@xuexi tmp]# sort uniq.txt | uniq  -D -c
    uniq: printing all duplicated lines and repeat counts is meaningless
    Try `uniq --help' for more information.
  • 相关阅读:
    第六天学习:Python数据类型(二)
    第五天学习:python数据类型(一)
    第四天学习:运算符
    第一天学习:python的安装及helloworld
    第二十五天学习:mysql(二)
    第二十四天学习:mysql(一)
    第二十三天学习:正则(2)
    第二十二天学习:正则
    第二十一天学习:模块(三)json
    第二十天学习:模块(二)
  • 原文地址:https://www.cnblogs.com/machangwei-8/p/9570964.html
Copyright © 2011-2022 走看看