天天看點

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
           

繼續閱讀