免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: linux_kaige
打印 上一主题 下一主题

awk过滤log的问题 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2012-01-08 12:27 |只看该作者
回复 9# yinyuemi
震惊!


   

论坛徽章:
0
12 [报告]
发表于 2012-01-08 13:01 |只看该作者
本帖最后由 linux_kaige 于 2012-01-08 13:02 编辑

回复 5# yinyuemi
你好,难的有个机会,得到高人相助,我就再问一下我的疑问,当然问问题,我也先自己看了下,问太白痴的问题,也不好意思,哈哈!就是执行了你写的那条awk,打印的结果里面,还能看到包含XmlParse.java:63的行。
  1. -bash-3.2$ cat cuawk.txt
  2. [INFO ] 2012-01-05 11:56:16,368  1791723191 [com.zxun.util.XmlParse.createXML(XmlParse.java:63)] method:开始创建xml...
  3. [INFO ] 2012-01-05 11:56:16,368  1791723191 [com.zxun.util.XmlParse.createXML(XmlParse.java:94)] method:创建XML成功,将doc---->String
  4. [INFO ] 2012-01-05 11:56:16,369  1791723192 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:8] method:【创建 xml 成功]
  5. [INFO ] 2012-01-05 11:56:43,632  1791750455 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:49)] method:收到软通接口调用信息
  6. [INFO ] 2012-01-05 11:56:43,632  1791750455 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:73)] method:COPID合法!开始查询数据库中数据!
  7. [INFO ] 2012-01-05 11:56:43,679  1791750502 [com.zxun.dao.impl.BaseDaoImpl.findAll(BaseDaoImpl.java:53)] method:resultList:7
  8. [INFO ] 2012-01-05 11:56:43,679  1791750502 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:77)] method:查询结果长度为:7
  9. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  10. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  11. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  12. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  13. [INFO ] 2012-01-05 11:56:43,698  1791750521 [com.zxun.util.XmlParse.createXML(XmlParse.java:)] method:开始创建xml...
  14. [INFO ] 2012-01-05 11:56:16,368  1791723191 [com.zxun.util.XmlParse.createXML(XmlParse.java:63)] method:开始创建xml...
  15. [INFO ] 2012-01-05 11:56:16,368  1791723191 [com.zxun.util.XmlParse.createXML(XmlParse.java:94)] method:创建XML成功,将doc---->String
  16. [INFO ] 2012-01-05 11:56:16,369  1791723192 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:8] method:【创建 xml 成功]
  17. [INFO ] 2012-01-05 11:56:43,632  1791750455 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:49)] method:收到软通接口调用信息
  18. [INFO ] 2012-01-05 11:56:43,632  1791750455 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:73)] method:COPID合法!开始查询数据库中数据!
  19. [INFO ] 2012-01-05 11:56:43,679  1791750502 [com.zxun.dao.impl.BaseDaoImpl.findAll(BaseDaoImpl.java:53)] method:resultList:7
  20. [INFO ] 2012-01-05 11:56:43,679  1791750502 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:77)] method:查询结果长度为:7
  21. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  22. [INFO ] 2012-01-05 11:56:43,698  1791750521 [com.zxun.util.XmlParse.createXML(XmlParse.java:63)] method:开始创建xml...
  23. [INFO ] 2012-01-05 11:56:16,368  1791723191 [com.zxun.util.XmlParse.createXML(XmlParse.java:63)] method:开始创建xml...
  24. [INFO ] 2012-01-05 11:56:16,368  1791723191 [com.zxun.util.XmlParse.createXML(XmlParse.java:94)] method:创建XML成功,将doc---->String
  25. [INFO ] 2012-01-05 11:56:16,369  1791723192 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:8] method:【创建 xml 成功]
  26. [INFO ] 2012-01-05 11:56:43,632  1791750455 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:49)] method:收到软通接口调用信息
  27. [INFO ] 2012-01-05 11:56:43,632  1791750455 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:73)] method:COPID合法!开始查询数据库中数据!
  28. [INFO ] 2012-01-05 11:56:43,679  1791750502 [com.zxun.dao.impl.BaseDaoImpl.findAll(BaseDaoImpl.java:53)] method:resultList:7
  29. [INFO ] 2012-01-05 11:56:43,679  1791750502 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:77)] method:查询结果长度为:7
  30. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  31. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  32. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  33. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  34. [INFO ] 2012-01-05 11:56:43,698  1791750521 [com.zxun.util.XmlParse.createXML(XmlParse.java:)] method:开始创建xml...
  35. [INFO ] 2012-01-05 11:56:16,368  1791723191 [com.zxun.util.XmlParse.createXML(XmlParse.java:63)] method:开始创建xml...
  36. [INFO ] 2012-01-05 11:56:16,368  1791723191 [com.zxun.util.XmlParse.createXML(XmlParse.java:94)] method:创建XML成功,将doc---->String
  37. [INFO ] 2012-01-05 11:56:16,369  1791723192 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:8] method:【创建 xml 成功]
  38. [INFO ] 2012-01-05 11:56:43,632  1791750455 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:49)] method:收到软通接口调用信息
  39. [INFO ] 2012-01-05 11:56:43,632  1791750455 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:73)] method:COPID合法!开始查询数据库中数据!
  40. [INFO ] 2012-01-05 11:56:43,679  1791750502 [com.zxun.dao.impl.BaseDaoImpl.findAll(BaseDaoImpl.java:53)] method:resultList:7
  41. [INFO ] 2012-01-05 11:56:43,679  1791750502 [com.zxun.servlet.SoftWareServlet.doPost(SoftWareServlet.java:77)] method:查询结果长度为:7
  42. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  43. [INFO ] 2012-01-05 11:56:43,698  1791750521 [com.zxun.util.XmlParse.createXML(XmlParse.java:63)] method:开始创建xml...
  44. -bash-3.2$
复制代码
  1. -bash-3.2$ awk '{if($0~/XmlParse.java:63/){for(i=1;i<=8;i++){getline}}}1' cuawk.txt
  2. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  3. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  4. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  5. [INFO ] 2012-01-05 11:56:43,698  1791750521 [com.zxun.util.XmlParse.createXML(XmlParse.java:)] method:开始创建xml...
  6. [INFO ] 2012-01-05 11:56:43,698  1791750521 [com.zxun.util.XmlParse.createXML(XmlParse.java:63)] method:开始创建xml...
  7. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  8. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  9. [INFO ] 2012-01-05 11:56:43,697  1791750520 [com.zxun.dao.impl.BaseDaoImpl.update(BaseDaoImpl.java:91)] method:update db failed.update tinformation ti set ti.dsissue = sysdate where ti.sonline=1 and ti.dsissue is null
  10. [INFO ] 2012-01-05 11:56:43,698  1791750521 [com.zxun.util.XmlParse.createXML(XmlParse.java:)] method:开始创建xml...
  11. [INFO ] 2012-01-05 11:56:43,698  1791750521 [com.zxun.util.XmlParse.createXML(XmlParse.java:63)] method:开始创建xml...
  12. -bash-3.2$
复制代码
有点不理解,方便的话还望解释一下!我看awk '{if($0~/XmlParse.java:63/){for(i=1;i<=8;i++){getline}}}1',我也看了一些getline的用法,当读入第一行的时候,if($0~/XmlParse.java:63/)为真,则执行8次getline么?(但是awk又是按行处理的脚本语言,执行当前行,自动跳过下面8行,那么下面的8行是否可以理解为awk未处理?)意思是如果当前行包含“XmlParse.java:63”,执行for,getline 8次,最后打印(else的内容)。但是我觉得结果里面不应该包含XmlParse.java:63的行了吧?是不是以为包含“XmlParse.java:63”。

谢谢


   

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
13 [报告]
发表于 2012-01-08 14:08 |只看该作者
本帖最后由 yinyuemi 于 2012-01-08 14:09 编辑

回复 12# linux_kaige

如果刚第8行是/XmlParse.java:63/的话,之前的代码会被print出来,因为getline改变当前的$0.试试这个行不,
  1. awk '/XmlParse.java:63/{for(i=1;i<=8;i++){getline};}!/XmlParse.java:63/'
复制代码
也可以试试这样:

  1. awk '/XmlParse.java:63/{p=1}!p||p++>9'
复制代码

论坛徽章:
0
14 [报告]
发表于 2012-01-08 15:43 |只看该作者
回复 13# yinyuemi
谢谢您,我终于看明白了,我的测试数据时那操蛋的log,看起来太恶心了,我用下面这个试了试,看起来直观一点:
  1. -bash-3.2$ seq -w 1  30 | awk '/3/{for(i=1;i<4;i++){getline}}1'
  2. 01
  3. 02
  4. 06
  5. 07
  6. 08
  7. 09
  8. 10
  9. 11
  10. 12
  11. 16
  12. 17
  13. 18
  14. 19
  15. 20
  16. 21
  17. 22
  18. 26
  19. 27
  20. 28
  21. 29
  22. 30
  23. -bash-3.2$
  24. -bash-3.2$ seq -w 1  30 | awk '/3/{for(i=1;i<4;i++){getline}}!/3/'
  25. 01
  26. 02
  27. 06
  28. 07
  29. 08
  30. 09
  31. 10
  32. 11
  33. 12
  34. 16
  35. 17
  36. 18
  37. 19
  38. 20
  39. 21
  40. 22
  41. 26
  42. 27
  43. 28
  44. 29
  45. -bash-3.2$ seq -w 1 30  | awk '/3/{p=1}!p||p++>3'
  46. 01
  47. 02
  48. 06
  49. 07
  50. 08
  51. 09
  52. 10
  53. 11
  54. 12
  55. 16
  56. 17
  57. 18
  58. 19
  59. 20
  60. 21
  61. 22
  62. 26
  63. 27
  64. 28
  65. 29
  66. -bash-3.2$
复制代码

论坛徽章:
0
15 [报告]
发表于 2012-01-08 17:37 |只看该作者
回复 3# waker
你好,本人水平有限,能发详细点的么?比如以
  1. -bash-3.2$ seq -w 1 30
  2. 01
  3. 02
  4. 03
  5. 04
  6. 05
  7. 06
  8. 07
  9. 08
  10. 09
  11. 10
  12. 11
  13. 12
  14. 13
  15. 14
  16. 15
  17. 16
  18. 17
  19. 18
  20. 19
  21. 20
  22. 21
  23. 22
  24. 23
  25. 24
  26. 25
  27. 26
  28. 27
  29. 28
  30. 29
  31. 30
  32. -bash-3.2$
复制代码
为例,如果包含3,那么删除它和它下面的两行。

谢谢!

   

论坛徽章:
14
处女座
日期:2013-11-26 09:21:15操作系统版块每日发帖之星
日期:2016-03-25 06:20:00操作系统版块每日发帖之星
日期:2016-03-22 06:20:00操作系统版块每日发帖之星
日期:2016-03-21 06:20:00数据库技术版块每日发帖之星
日期:2015-11-13 06:20:00操作系统版块每日发帖之星
日期:2015-11-01 06:20:002015亚冠之卡尔希纳萨夫
日期:2015-09-29 13:31:42IT运维版块每日发帖之星
日期:2015-08-13 06:20:00IT运维版块每日发帖之星
日期:2015-08-10 06:20:00数据库技术版块每日发帖之星
日期:2015-08-06 06:20:00双鱼座
日期:2014-07-17 15:08:51卯兔
日期:2014-04-08 09:54:34
16 [报告]
发表于 2012-01-09 11:02 |只看该作者
回复 9# yinyuemi


    能简单解释下吗,前面是过滤,后面+7d是什么啊,该不是删除吧

论坛徽章:
0
17 [报告]
发表于 2012-01-09 13:11 |只看该作者
回复 16# royzs
是删除。。。


   

论坛徽章:
14
处女座
日期:2013-11-26 09:21:15操作系统版块每日发帖之星
日期:2016-03-25 06:20:00操作系统版块每日发帖之星
日期:2016-03-22 06:20:00操作系统版块每日发帖之星
日期:2016-03-21 06:20:00数据库技术版块每日发帖之星
日期:2015-11-13 06:20:00操作系统版块每日发帖之星
日期:2015-11-01 06:20:002015亚冠之卡尔希纳萨夫
日期:2015-09-29 13:31:42IT运维版块每日发帖之星
日期:2015-08-13 06:20:00IT运维版块每日发帖之星
日期:2015-08-10 06:20:00数据库技术版块每日发帖之星
日期:2015-08-06 06:20:00双鱼座
日期:2014-07-17 15:08:51卯兔
日期:2014-04-08 09:54:34
18 [报告]
发表于 2012-01-09 13:21 |只看该作者
回复 17# linux_kaige


       那加号呢,加号的意思是什么啊

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
19 [报告]
发表于 2012-01-09 13:53 |只看该作者
回复 18# royzs


   
`ADDR1,+N'
     Matches ADDR1 and the N lines following ADDR1.

论坛徽章:
14
处女座
日期:2013-11-26 09:21:15操作系统版块每日发帖之星
日期:2016-03-25 06:20:00操作系统版块每日发帖之星
日期:2016-03-22 06:20:00操作系统版块每日发帖之星
日期:2016-03-21 06:20:00数据库技术版块每日发帖之星
日期:2015-11-13 06:20:00操作系统版块每日发帖之星
日期:2015-11-01 06:20:002015亚冠之卡尔希纳萨夫
日期:2015-09-29 13:31:42IT运维版块每日发帖之星
日期:2015-08-13 06:20:00IT运维版块每日发帖之星
日期:2015-08-10 06:20:00数据库技术版块每日发帖之星
日期:2015-08-06 06:20:00双鱼座
日期:2014-07-17 15:08:51卯兔
日期:2014-04-08 09:54:34
20 [报告]
发表于 2012-01-09 15:18 |只看该作者
yinyuemi 发表于 2012-01-09 13:53
回复 18# royzs


你们都太厉害了,我小白哇
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP