linux命令之uniq
linux命令uniq是用来删除经过排序后的数据的重复记录。uniq去重只能去除连续的重复行,所以一般先用sort排序,再去重统计重复的数据
uniq [参数]
| 参数 | 说明 |
| -c | 统计重复的数据 |
命令:
cat access.log | awk '{print $9}' | sort | uniq -c
- [root@centos79 nginx]# pwd
- /var/log/nginx
- [root@centos79 nginx]# ls
- access.log error.log
- [root@centos79 nginx]# cat access.log | awk '{print $9}' | sort | uniq -c
- 4 200
- 2 404
- [root@centos79 nginx]#
命令:
cat access.log | awk '{print $1}' | uniq -c | sort -nr
- [root@centos79 nginx]# pwd
- /var/log/nginx
- [root@centos79 nginx]# ls
- access.log error.log
- [root@centos79 nginx]# cat access.log | awk '{print $1}' | uniq -c | sort -nr
- 6 192.168.10.1
- [root@centos79 nginx]#
命令:
cat /etc/passwd | cut -d: -f 7 | uniq -c | sort -nr
- [root@centos79 nginx]# cat /etc/passwd | cut -d: -f 7 | uniq -c | sort -nr
- 36 /sbin/nologin
- 4 /sbin/nologin
- 4 /bin/bash
- 2 /bin/bash
- 1 /sbin/shutdown
- 1 /sbin/nologin
- 1 /sbin/halt
- 1 /bin/sync
- 1 /bin/bash
- [root@centos79 nginx]#
命令:
cat access.log |awk '{print $1,$9}' | uniq -c | sort -r | head -2
- [root@cent79-2 nginx]# cat access.log |awk '{print $1,$9}' | uniq -c | sort -r | head -2
- 4 192.168.10.1 200
- 2 192.168.10.1 404
- [root@cent79-2 nginx]#