• 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

    1. [root@centos79 nginx]# pwd
    2. /var/log/nginx
    3. [root@centos79 nginx]# ls
    4. access.log error.log
    5. [root@centos79 nginx]# cat access.log | awk '{print $9}' | sort | uniq -c
    6. 4 200
    7. 2 404
    8. [root@centos79 nginx]#

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

    命令:

    cat access.log | awk '{print $1}' | uniq -c | sort -nr

    1. [root@centos79 nginx]# pwd
    2. /var/log/nginx
    3. [root@centos79 nginx]# ls
    4. access.log error.log
    5. [root@centos79 nginx]# cat access.log | awk '{print $1}' | uniq -c | sort -nr
    6. 6 192.168.10.1
    7. [root@centos79 nginx]#

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

    命令:

    cat /etc/passwd | cut -d: -f 7 | uniq -c | sort -nr
     

    1. [root@centos79 nginx]# cat /etc/passwd | cut -d: -f 7 | uniq -c | sort -nr
    2. 36 /sbin/nologin
    3. 4 /sbin/nologin
    4. 4 /bin/bash
    5. 2 /bin/bash
    6. 1 /sbin/shutdown
    7. 1 /sbin/nologin
    8. 1 /sbin/halt
    9. 1 /bin/sync
    10. 1 /bin/bash
    11. [root@centos79 nginx]#

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

    命令:

    cat access.log |awk '{print $1,$9}' | uniq -c | sort -r | head -2

    1. [root@cent79-2 nginx]# cat access.log |awk '{print $1,$9}' | uniq -c | sort -r | head -2
    2. 4 192.168.10.1 200
    3. 2 192.168.10.1 404
    4. [root@cent79-2 nginx]#

  • 相关阅读:
    Java注解
    Element Plus 全球化配置
    Postgresql JSON对象和数组查询
    计算机后端常用软件
    成集云 | 成集云-经销商返利系统集成金蝶云星辰 | 解决方案
    修改了Excel默认打开方式后仍然使用WPS打开的解决办法
    Redis
    flink-sql写入hudi的行列转换lateral
    【译】.NET 7 中的性能改进(十二)
    ICMP报文
  • 原文地址:https://blog.csdn.net/z19861216/article/details/132812097