博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux中的 awk查找日志中的相关记录
阅读量:6333 次
发布时间:2019-06-22

本文共 2373 字,大约阅读时间需要 7 分钟。

假设要在 api.log.201707201830 文件中,(此文件的多个字段数据以不可见字符^A(键盘上按下Ctrl+V+A)分隔),要输出第70个字段:

awk -F '^A' '{print $70}' api.log.201707201830

要判断第25个字段=9的数据,输出第70个字段:

awk -F '^A' '($25==9){print $70}' api.log.201707201830

如果判断的值是字符串,就要加双引号(此案例以\x01分隔)

awk -F '\x01' '($1=="a17cdca4daa7a92e473dc1a532da5aaf"){print $1}' yumiad_event.2017072016

如果是判断多个条件,用&&连接 

awk -F '\x01' '($1=="a17cdca4daa7a92e473dc1a532da5aaf" && $14==10026 && $13==8){print $1,$2,$5,$14,$13}' yumiad_event.2017072016

 


 

对于没有固定分隔符的数据,可以使用grep:

如下案例表示在下面格式的很大的日志文件中查找 cornID=xyz 并且 adType=8 并且 providerID=10026:

mediation/report_partner.php           partnerID=10002&uuid=8b633a6e57060f841ffc35106472810a&cornID=a17cdca4daa7a92e473dc1a532da5aaf&versionID=-&channelID=-&deviceType=3&mac=9c%3A41%3A7c%3A76%3A44%3A20&deviceKey=356405052830313&time=1500537724706&os=android&netType=wifi&deviceNo=GT-N7108&language=zh_CN&longitude=-&latitude=-&planTime=1499323004&optimization=0&PLMN=46003&sdkver=160&rid=a8d3d425f883fce0e64bc25469890e84&androidID=75673d3aa19fb2ac&trans=abc%2Cdef%2Cghi&ad_list=%5B%7B%22clickArea%22%3A%7B%7D%2C%22result%22%3A%221%22%2C%22interfaceType%22%3A%22API%22%2C%22keyID%22%3A%22%22%2C%22action%22%3A%22request%22%2C%22pid%22%3A%2280cd137fd603fb5f0685020ae0092a9d%22%2C%22eventTime%22%3A%221500537724346%22%2C%22providerID%22%3A%2210026%22%2C%22adType%22%3A%222%22%7D%2C%7B%22clickArea%22%3A%7B%7D%2C%22result%22%3A%221%22%2C%22interfaceType%22%3A%22API%22%2C%22keyID%22%3A%22%22%2C%22action%22%3A%22response%22%2C%22pid%22%3A%2280cd137fd603fb5f0685020ae0092a9d%22%2C%22eventTime%22%3A%221500537724691%22%2C%22providerID%22%3A%2210026%22%2C%22adType%22%3A%222%22%7D%2C%7B%22clickArea%22%3A%7B%7D%2C%22result%22%3A%221%22%2C%22interfaceType%22%3A%22API%22%2C%22keyID%22%3A%22%22%2C%22action%22%3A%22exposure%22%2C%22pid%22%3A%2280cd137fd603fb5f0685020ae0092a9d%22%2C%22eventTime%22%3A%221500537724692%22%2C%22providerID%22%3A%2210026%22%2C%22adType%22%3A%222%22%7D%2C%7B%22clickArea%22%3A%7B%7D%2C%22result%22%3A%221%22%2C%22interfaceType%22%3A%22API%22%2C%22keyID%22%3A%22%22%2C%22action%22%3A%22round%22%2C%22pid%22%3A%2280cd137fd603fb5f0685020ae0092a9d%22%2C%22eventTime%22%3A%221500537724692%22%2C%22providerID%22%3A%2210026%22%2C%22adType%22%3A%222%22%7D%5D   

查询命令:

cat api.2017072016.log | grep -i 'cornID=xyz' | grep -i 'adType=8' | grep -i 'providerID=10026' 

 

转载于:https://www.cnblogs.com/rxbook/p/7216735.html

你可能感兴趣的文章
js作用域链
查看>>
java中如何选择Collection Class--java线程(第3版)
查看>>
为运维人员插上腾飞更远的翅膀!
查看>>
Word 2003中编辑标记与格式标记大讨论
查看>>
从国内向海外转移域名经验谈
查看>>
浅谈apache与tomact的整合
查看>>
SQL Server vNext CTP1 on Linux
查看>>
1-为 Lync Server 2010 准备 Active Directory 域服务
查看>>
NetBackup下ORACLE恢复测试方案实例解析
查看>>
【有奖征文】“失业”程序员的苦辣酸甜
查看>>
IE9是如何被FireFox4超越全球市场份额的?
查看>>
linux bunzip2命令
查看>>
敏捷个人:通过实践TOGAF来思考如何学习并应用新的方法?
查看>>
Android系统的开机画面显示过程分析(6)
查看>>
vivo Hi-Fi+QQ音乐 数字音乐市场的一剂良方
查看>>
Cocos2d-x 3.2 异步动态加载 -- 保卫萝卜开发总结
查看>>
聚焦触宝反侵权事件:中国创业者用什么护航海外市场大门
查看>>
AOP技术基础
查看>>
Android系统进程间通信(IPC)机制Binder中的Server启动过程源代码分析(2)
查看>>
无线802.11n 2.4G与5G性能测试
查看>>