Linux命令(84)之uniq

linux命令之uniq

1.uniq介绍

linux命令uniq是用来删除经过排序后的数据的重复记录。uniq去重只能去除连续的重复行,所以一般先用sort排序,再去重统计重复的数据

2.uniq用法

uniq [参数]

uniq参数
参数 说明
-c 统计重复的数据

3.实例

3.1.统计http access.log文件中状态码

命令:

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]# 

3.2.统计http access.log文件中谁访问过网站

命令:

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]# 

3.3.统计/etc/passwd中每种shell的使用情况

命令:

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]# 

3.4.统计http access.log文件中访问次数最多的前两个ip地址,以及出现次数最多的两个状态码

命令:

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]# 

文章来源地址https://uudwc.com/A/9d1GV

原文地址:https://blog.csdn.net/z19861216/article/details/132812097

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请联系站长进行投诉反馈,一经查实,立即删除!

h
上一篇 2023年09月25日 06:42
关于地址存放的例题
下一篇 2023年09月25日 06:42