uniq命令的使用:
uniq 命令用于检查及删除文本文件中重复出现的行列,一般与 sort 命令结合使用。
uniq 可检查文本文件中重复出现的行列。
参数:
-c 或 --count 在每列旁边显示该行重复出现的次数。
-d 或 --repeated 仅显示重复出现的行列。
-u 或 --unique 仅显示出现一次的行列
#排序后删除重复行
cat test.txt |sort |uniq
#排序之后删除重复行,同时在行首位置输出重复行的次数
cat test.txt |sort |uniq -c
#仅显示存在重复的行,并在行首显示该行重复的次数
cat test.txt |sort |uniq -dc
#仅显示不重复的行
cat test.txt |sort|uniq -u
例如:
nginx日志分析----统计某个时间段的IP
grep "23/Apr/2020:2[0-3]" nowcoder.txt | awk '{print $1}' | sort | uniq | wc -l