linux grep 取出特定字符串并统计个数

原始日志如下:

$more text.log
2018-07-16 00:00:03 [DEBUG] request setInformation params:{"msg":"{\"to\":\"3685836021744CCAA36A8D11759A336F\",\"msgStamp\":\"1531670403377\",\"msgId\":\"a1e910cffcec45ba9c0a59e73a250ffe\",\"msgTxt\":\"{\\\"template\\\":\\\"{\\\\\\\"controlInfo\\\\\\\":{\\\\\\\"like\\\\\\\":false,\\\\\\\"loop\\\\\\\":false,\\\\\\\"state\\\\\\\":\\\\\\\"PAUSED\\\\\\\"},\\\\\\\"titleButtons\\\\\\\":[{\\\\\\\"imageUrl\\\\\\\":\\\\\\\"https://s.xxxcdn.com/mobile-app/icon/media/media_player_album.png\\\\\\\",\\\\\\\"linkUrl\\\\\\\":\\\\\\\"xxx://media/v3/detail?id=2998398&appId=RC528E2DD8E745E195173D9F8BE48436&style=planB\\\\\\\"}],\\\\\\\"appId\\\\\\\":\\\\\\\"RC528E2DD8E745E195173D9F8BE48436\\\\\\\",\\\\\\\"style\\\\\\\":\\\\\\\"planB\\\\\\\",\\\\\\\"item\\\\\\\":{\\\\\\\"id\\\\\\\":\\\\\\\"9766476\\\\\\\",\\\\\\\"title\\\\\\\":\\\\\\\"为何\\\\u201c双1
1\\\\u201c苏宁对掐京东?\\\\\\\",\\\\\\\"subtitle\\\\\\\":\\\\\\\"元气少女情报局\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"link\\\\\\\",\\\\\\\"imageType\\\\\\\":\\\\\\\"circle\\\\\\\",\\\\\\\"imageUrl\\\\\\\":\\\\\\\"http://fdfs.xmcdn.com/group13/M04/78/3F/wKgDXlYFJo6w5U8XAAG459Xxv6M451_mobile_large.jpg\\\\\\\",\\\\\\\"extend\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"offset\\\\\\\":\\\\\\\"287\\\\\\\",\\\\\\\"duration\\\\\\\":\\\\\\\
"287\\\\\\\"},\\\\\\\"copyright\\\\\\\":{\\\\\\\"summary\\\\\\\":\\\\\\\"内容来自:喜马拉雅\\\\\\\",\\\\\\\"iconUrl\\\\\\\":\\\\\\\"\\\\\\\"}}\\\",\\\"event\\\":\\\"ON_PAUSED\\\",\\\"appid\\\":\\\"RC528E2DD8E745E195173D9F8BE48436\\\",\\\"type\\\":\\\"Media\\\",\\\"version\\\":\\\"3.0.0\\\"}\",\"from\":\"0302041802012703\",\"msgTopic\":\"event\"}"}
2018-07-16 00:00:03 [DEBUG] request setInformation params:{"msg":"{\"msgStamp\":\"1531670352272\",\"msgId\":\"CC5D2215C8C04557A8005C1C8E6251E2\",\"from\":\"E33FCE60E7294A61B84C43C1A171DFD8\",\"to\":\"79EB05248A8938E6E9474C8ECA4CA774\",\"msgTxt\":\"{\\n \\\"type\\\": \\\"chat\\\",\\n \\\"template\\\": \\\"{\\\\\\\"tts\\\\\\\":\\\\\\\"在呢\\\\\\\"}\\\",\\n \\\"appid\\\": \\\"E33FCE60E7294A61B84C43C1A171DFD8\\\",\\n \\\"feedback\\\": {\\n \\\"voiceUrl\\\": \\\"\\\",\\n \\\"voice\\\": \\\"若琪\\\"\\n }\\n }\",\"msgTopic\":\"card\"}"}

要获取每个appid的次数

grep '"appid\\\\\\":\\\\\\"[^"]*' -o text.log| sort | uniq -c | sort -rn

结果如下:

   2313 "appid\\\":\\\"RC528E2DD8E745E195173D9F8BE48436\\\
1855 "appid\\\":\\\"R165ECD08C90491B89C809753D1F322F\\\
1841 "appid\\\":\\\"R40913E89BFF4C79A210418E6E5BE663\\\
478 "appid\\\":\\\"R9EDC9514BED480BA97E0C3BEC7A7828\\\
423 "appid\\\":\\\"R7C638312DA94C54BFE5B3BE2FE33E44\\\
384 "appid\\\":\\\"com.xxx.homebase\\\
359 "appid\\\":\\\"R233A4F187F34C94B93EE3BAECFCE2E3\\\
14 "appid\\\":\\\"E33FCE60E7294A61B84C43C1A171DFD8\\\
10 "appid\\\":\\\"R786530EA1884AACA79792C04A833885\\\
1 "appid\\\":\\\"1106500120\\\

感谢老神医!

谢谢

上一篇:识别Json字符串并分隔成Map集合


下一篇:201521123061 《Java程序设计》第十周学习总结