天天看点

sort使用,uniq去重统计

sort 排序

语法格式:
			  sort [参数选项] file
			  cat file|sort [参数选项]

1.sort默认按照第一列进行排序 
a. 第一列的第一个字母 a..z 正序排序
b. 第一列的第一个数字 从小到大正序排序
c.若是第一列有数字有字母,数字在前
              参数选项:
              -r  #逆序排列
              -n  #按照数字正常大小排序
              -kn  #按照第n列排序
           

uniq

去重 
统计 
定义:默认去重(把挨着的 相邻的和自己一模一样的单词进行去重)
参数选项:
		-c 统计去重次数
           

案例:

作业: 统计出以下域名各出现了多少次  按照出现次数最多的进行排序
//把以下内容复制到文件中  先取出过滤域名 然后进行域名的次数统计
cat oldboy.txt 
http://www.baidu.com/images/jpg
http://www.sina.com/images/mp4
http://www.baidu.com/static/index.html
http://www.weibo.com/index.html
http://www.sina.com/static/jpg
http://www.baidu.com/index.html
http://www.sina.com/test/index.html
[[email protected] alex]# awk -F/ '{print $3}' 1.txt |sort|uniq -c
 3 www.baidu.com
 3 www.sina.com
 1 www.weibo.com
           

继续阅读