uniq 去除重复行或统计

uniq 去除重复行或统计
主要选项
-u (唯一)和 -d (重复) -c (统计) -f (跳过字段数,默认tab标示)  -s (同f,单位字符)
1.同样记录打印一次(必须是排好序)
 sort  a.txt |uniq 或
 sort -u a.txt -o b.txt

[root@M165 root]# cat a.txt           
a b 2
a b 4
a b 2
a d 4
a b 4
统计重复行
[root@M165 root]# sort a.txt |uniq -dc
      2 a b 2
      2 a b 4
统计单独行,不懂为什么有uniq -uc
[root@M165 root]# sort a.txt |uniq -uc
      1 a d 4
分别统计
[root@M165 root]# sort a.txt |uniq -c
      2 a b 2
      2 a b 4
      1 a d 4

[root@M165 root]# tail -5 install.log.syslog 
<13>Aug 21 16:01:28 kudzu: aliased usb-controller1 as ehci-hcd
<13>Aug 21 16:01:29 kudzu: aliased usb-controller1 as ehci-hcd
<13>Aug 21 16:01:20 kudzu: aliased usb-controller1 as ehci-hcd
<13>Aug 22 16:01:20 kudzu: aliased usb-controller1 as ehci-hcd
<14>Aug 22 16:01:20 kudzu: aliased usb-controller1 as ehci-hcd
不对比第一字段<13>Aug
[root@M165 root]# tail -5 install.log.syslog |uniq -f 1
<13>Aug 21 16:01:28 kudzu: aliased usb-controller1 as ehci-hcd
<13>Aug 21 16:01:29 kudzu: aliased usb-controller1 as ehci-hcd
<13>Aug 21 16:01:20 kudzu: aliased usb-controller1 as ehci-hcd
<13>Aug 22 16:01:20 kudzu: aliased usb-controller1 as ehci-hcd
不对比第二字段21
[root@M165 root]# tail -5 install.log.syslog |uniq -f 2
<13>Aug 21 16:01:28 kudzu: aliased usb-controller1 as ehci-hcd
<13>Aug 21 16:01:29 kudzu: aliased usb-controller1 as ehci-hcd
<13>Aug 21 16:01:20 kudzu: aliased usb-controller1 as ehci-hcd
不对比第二字段 16:01:28
[root@M165 root]# tail -5 install.log.syslog |uniq -f 3
<13>Aug 21 16:01:28 kudzu: aliased usb-controller1 as ehci-hcd
[root@M165 root]# tail -5 install.log.syslog |uniq -f 4
<13>Aug 21 16:01:28 kudzu: aliased usb-controller1 as ehci-hcd
用字符作单位
[root@M165 root]# tail -5 install.log.syslog |uniq -s 9
<13>Aug 21 16:01:28 kudzu: aliased usb-controller1 as ehci-hcd
<13>Aug 21 16:01:29 kudzu: aliased usb-controller1 as ehci-hcd
<13>Aug 21 16:01:20 kudzu: aliased usb-controller1 as ehci-hcd
<13>Aug 22 16:01:20 kudzu: aliased usb-controller1 as ehci-hcd
[root@M165 root]# tail -5 install.log.syslog |uniq -s 10
<13>Aug 21 16:01:28 kudzu: aliased usb-controller1 as ehci-hcd
<13>Aug 21 16:01:29 kudzu: aliased usb-controller1 as ehci-hcd
<13>Aug 21 16:01:20 kudzu: aliased usb-controller1 as ehci-hcd

你可能感兴趣的:(uniq 去除重复行或统计)