shell-sort-wc-uniq

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

[b]2、cut分割[/b]

-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


[b]3、排序-sort[/b]

-b 忽略每行前面开始出的空格字符。
-c 检查文件是否已经按照顺序排序。
-f 排序时,忽略大小写字母。
-M 将前面3个字母依照月份的缩写进行排序。
-n 依照数值的大小排序。
-o<输出文件> 将排序后的结果存入指定的文件。
-r 以相反的顺序来排序。
-t<分隔字符> 指定排序时所用的栏位分隔字符。
-k 选择以哪个区间进行排序。


cut -d. -f2 domain.txt |sort


[b]4、取唯一值-uniq[/b]

默认输出唯一行

-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


[b]5、再排序-sort[/b]

-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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值