linux字符串分组,centos下对文件某些特定字符串分组统计出现次数

假如现有数据:

{ "@timestamp": "2018-10-13t21:55:58+08:00", "remote_addr": "100.120.34.3", "referer": "-", "request": "get /api/gourd/activeupload?idfa=58237fa9-a1b3-4202-b5f3-9536983119e5&appid=1410137206&source=rehulu http/1.1", "status": 200, "request_time": 0.076, "cookie":"-","host":"cms.369wan.com","bytes": 48, "agent": "mozilla/5.0 (x11; ubuntu; linux x86_64; rv:18.0) gecko/20100101 firefox/18.0", "proxy_x_forwarded": "139.129.97.187, 100.120.34.3" "upstr_addr": "127.0.0.1:9000","upstr_host": "-","ups_resp_time": 0.076 }

{ "@timestamp": "2018-10-13t21:56:06+08:00", "remote_addr": "100.120.34.101", "referer": "-", "request": "get /api/gourd/activeupload?idfa=e9d7f87a-9042-46b4-82e8-e5f64b74466b&appid=1410137206&source=rehulu http/1.1", "status": 200, "request_time": 0.076, "cookie":"-","host":"cms.369wan.com","bytes": 48, "agent": "mozilla/5.0 (x11; ubuntu; linux x86_64; rv:18.0) gecko/20100101 firefox/18.0", "proxy_x_forwarded": "139.129.97.187, 100.120.34.101" "upstr_addr": "127.0.0.1:9000","upstr_host": "-","ups_resp_time": 0.076 }

{ "@timestamp": "2018-10-13t21:56:08+08:00", "remote_addr": "100.120.34.29", "referer": "-", "request": "get /api/gourd/activeupload?idfa=d5b924f3-7d25-4b52-bae9-3270b08ea32d&appid=1410137206&source=rehulu http/1.1", "status": 200, "request_time": 0.075, "cookie":"-","host":"cms.369wan.com","bytes": 48, "agent": "mozilla/5.0 (x11; ubuntu; linux x86_64; rv:18.0) gecko/20100101 firefox/18.0", "proxy_x_forwarded": "139.129.97.187, 100.120.34.29" "upstr_addr": "127.0.0.1:9000","upstr_host": "-","ups_resp_time": 0.075 }

{ "@timestamp": "2018-10-13t21:56:10+08:00", "remote_addr": "100.120.34.75", "referer": "-", "request": "get /api/gourd/activeupload?idfa=d166459d-e823-4847-9094-6f4bf90625b2&appid=1410137206&source=rehulu http/1.1", "status": 200, "request_time": 0.078, "cookie":"-","host":"cms.369wan.com","bytes": 48, "agent": "mozilla/5.0 (x11; ubuntu; linux x86_64; rv:18.0) gecko/20100101 firefox/18.0", "proxy_x_forwarded": "139.129.97.187, 100.120.34.75" "upstr_addr": "127.0.0.1:9000","upstr_host": "-","ups_resp_time": 0.078 }

{ "@timestamp": "2018-10-13t21:56:18+08:00", "remote_addr": "100.120.34.39", "referer": "-", "request": "get /api/gourd/activeupload?idfa=08c65c3b-eed2-4a65-b0c1-67fc7fb78e18&appid=1410137206&source=rehulu http/1.1", "status": 200, "request_time": 0.082, "cookie":"-","host":"cms.369wan.com","bytes": 48, "agent": "mozilla/5.0 (x11; ubuntu; linux x86_64; rv:18.0) gecko/20100101 firefox/18.0", "proxy_x_forwarded": "139.129.97.187, 100.120.34.39" "upstr_addr": "127.0.0.1:9000","upstr_host": "-","ups_resp_time": 0.082 }

{ "@timestamp": "2018-10-13t21:56:31+08:00", "remote_addr": "100.120.34.68", "referer": "-", "request": "get /api/gourd/activeupload?idfa=d5b924f3-7d25-4b52-bae9-3270b08ea32d&appid=1410137206&source=rehulu http/1.1", "status": 200, "request_time": 0.079, "cookie":"-","host":"cms.369wan.com","bytes": 48, "agent": "mozilla/5.0 (x11; ubuntu; linux x86_64; rv:18.0) gecko/20100101 firefox/18.0", "proxy_x_forwarded": "139.129.97.187, 100.120.34.68" "upstr_addr": "127.0.0.1:9000","upstr_host": "-","ups_resp_time": 0.079 }

临时保存为tmp.log

awk -f 'idfa=' '{print $2}' tmp.log

出现如下结果:

58237fa9-a1b3-4202-b5f3-9536983119e5&appid=1410137206&source=rehulu http/1.1", "status": 200, "request_time": 0.076, "cookie":"-","host":"cms.369wan.com","bytes": 48, "agent": "mozilla/5.0 (x11; ubuntu; linux x86_64; rv:18.0) gecko/20100101 firefox/18.0", "proxy_x_forwarded": "139.129.97.187, 100.120.34.3" "upstr_addr": "127.0.0.1:9000","upstr_host": "-","ups_resp_time": 0.076 }

e9d7f87a-9042-46b4-82e8-e5f64b74466b&appid=1410137206&source=rehulu http/1.1", "status": 200, "request_time": 0.076, "cookie":"-","host":"cms.369wan.com","bytes": 48, "agent": "mozilla/5.0 (x11; ubuntu; linux x86_64; rv:18.0) gecko/20100101 firefox/18.0", "proxy_x_forwarded": "139.129.97.187, 100.120.34.101" "upstr_addr": "127.0.0.1:9000","upstr_host": "-","ups_resp_time": 0.076 }

d5b924f3-7d25-4b52-bae9-3270b08ea32d&appid=1410137206&source=rehulu http/1.1", "status": 200, "request_time": 0.075, "cookie":"-","host":"cms.369wan.com","bytes": 48, "agent": "mozilla/5.0 (x11; ubuntu; linux x86_64; rv:18.0) gecko/20100101 firefox/18.0", "proxy_x_forwarded": "139.129.97.187, 100.120.34.29" "upstr_addr": "127.0.0.1:9000","upstr_host": "-","ups_resp_time": 0.075 }

执行

awk -f 'idfa=' '{print $2}' tmp.log | awk -f '&source=' '{print $1}'

出现如下结果:

58237fa9-a1b3-4202-b5f3-9536983119e5&appid=1410137206

e9d7f87a-9042-46b4-82e8-e5f64b74466b&appid=1410137206

d5b924f3-7d25-4b52-bae9-3270b08ea32d&appid=1410137206

执行

awk -f 'idfa=' '{print $2}' tmp.log | awk -f '&source=' '{print $1}'  | sort  (这一步将结果相同的放在一起)

出现如下结果:

58237fa9-a1b3-4202-b5f3-9536983119e5&appid=1410137206

e9d7f87a-9042-46b4-82e8-e5f64b74466b&appid=1410137206

d5b924f3-7d25-4b52-bae9-3270b08ea32d&appid=1410137206

执行

awk -f 'idfa=' '{print $2}' cms_\(2\).log | awk -f '&source=' '{print $1}' |sort| uniq -c

出现最终结果(次数 和 各字符串):

1 58237fa9-a1b3-4202-b5f3-9536983119e5&appid=1410137206

1 e9d7f87a-9042-46b4-82e8-e5f64b74466b&appid=1410137206

1 d5b924f3-7d25-4b52-bae9-3270b08ea32d&appid=1410137206

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值