shell-sort-wc-uniq

1、准备数据
格式:
pgj.trade.baidu.com
chy.guoji.baidu.com
ndd.trade.baidu.com
cmt.trade.baidu.com
....

2、cut分割

-d, --delimiter=DELIM use DELIM instead of TAB for field delimiter

-f, --fields=LIST select  only  these  fields;   also  print any line that contains no delimiter character, unless the -s option is specified

 cut -d. -f2 domain.txt 


3、排序-sort
cut -d. -f2 domain.txt |sort


4、取唯一值-uniq

默认输出唯一行

-c, --count  prefix lines by the number of occurrences
-d, --repeated  only print duplicate lines
-u, --unique  only print unique lines

  cut -d. -f2 domain.txt |sort|uniq -c


5、再排序-sort

-t, --field-separator=SEP 指定分隔符 use SEP instead of non-blank to blank transition
-n, --numeric-sort 按数字格式排序 compare according to string numerical value
-f, --ignore-case 不考虑大小写  fold lower case to upper case characters
-r, --reverse 反转 reverse the result of comparisons

-g, --general-numeric-sort  compare according to general numerical value

cut -d. -f2 domain.txt |sort|uniq -c|sort -n
cut -d. -f2 domain.txt |sort|uniq -c|sort -nr
cut -d. -f2 domain.txt |sort |uniq -c|sort -g
cut -d. -f2 domain.txt |sort|uniq -c|sort -nr|head -2
sort domain.txt -t. -k2


-k:指定排序的字符开始和结束位置
-k, --key=POS1[,POS2]  start a key at POS1, end it at POS2 (origin 1)

data:
12.12.45.4
36.415.545.45
9.45.15.15
154.45.45
 sort a.txt -t. -k2

output:
12.12.45.4
36.415.545.45
9.45.15.15
154.45.45
 sort a.txt -t. -k1

output:
12.12.45.4
154.45.45
36.415.545.45
9.45.15.15

case:
atnodes "zgrep validateOrder.jsp /server/tts/logs/tts.log.2014-10-30-1*.gz" l-ttsi[1-10].f.cn1 |grep "RequestError"|awk -F '&id=' '{print $2}'|awk -F'&' '{print $1}'|sort|uniq|wc

你可能感兴趣的:(shell,sort,uniq,wc,cut)