排序与计数命令实践(sort、uniq)

处理以下文件内,将域名取出并根据域名进行计数排序处理:(百度和sohu面试题)
test.log
http://www.etiantian.org/index.html
http://www.etiantian.org/1.thml
http://post.etiantian.org/index.html
http://mp3.etiantian.org/index.html
http://www.etiantian.org/3.html
http://post.etiantian.org/2.html


处理方法一:
[root@machine1 ~]# cut -d "/"  -f 3 test.log |sort|uniq -c
      1 mp3.etiantian.org
      2 post.etiantian.org
      3 www.etiantian.org
其中:
cut -d 为指定分隔符, -f 为指定要打印的列数。
sort 为排序,就是把重复的放在一起。
uniq 为去重。-c 显示重复多少次的次数。
处理方法二:
[root@machine1 ~]# awk -F '/' '{print $3}' test.log|sort|uniq -c
      1 mp3.etiantian.org
      2 post.etiantian.org
      3 www.etiantian.org
其中:
awk -F 指定分割符,print $3为打赢第三列。
sort 为排序,就是把重复的放在一起。
uniq 为去重。-c 显示重复多少次的次数。

你可能感兴趣的:(Linux学习笔记)