去除文件重复行
1)提取测试文件
[root@svr5 ~]# awk -F: '{print $7}' /etc/passwd > a1.txt
[root@svr5 ~]# cat a1.txt
/bin/bash
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/bin/sync
/sbin/shutdown
/sbin/halt
/sbin/nologin
/sbin/nologin
.. ..
[root@svr5 ~]#
2)去除a1.txt文件中的重复行,另存为a2.txt
[root@svr5 ~]# awk '!a[$0]++' a1.txt > a2.txt
[root@svr5 ~]# cat a2.txt
/bin/bash
/sbin/nologin
/bin/sync
/sbin/shutdown
/sbin/halt
[root@svr5 ~]#
统计Web访问量排名
分步测试、验证效果如下所述。
1)提取IP地址及访问量
[root@svr5 ~]# awk '{ip[$1]++} END{for(i in ip) {print i,ip[i]}}' /var/log/httpd/access_log
127.0.0.1 4
192.168.4.5 17
192.168.4.110 13
.. ..
2)对第1)步的结果根据访问量排名
[root@svr5 ~]# awk '{ip[$1]++} END{for(i in ip) {print i,ip[i]}}' /var/log/httpd/access_log | sort -nr -k 2
192.168.4.5 17
192.168.4.110 13
127.0.0.1 4
.. ..
博客主要介绍了两项信息技术操作。一是去除文件重复行,先提取测试文件,再去除a1.txt文件中的重复行并另存为a2.txt;二是统计Web访问量排名,先提取IP地址及访问量,再根据访问量对结果进行排名。

被折叠的 条评论
为什么被折叠?



