免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1364 | 回复: 7
打印 上一主题 下一主题

请教文本处理 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-07-13 17:59 |只看该作者 |倒序浏览
例如:

Message Queue facility inactive.
T         ID      KEY        MODE        OWNER    GROUP
Shared Memory:
m          100   0x500003c4 --rw-r--r--     root     root
m           1234 0x500003c3 --rw-r--r--    test      test
Test   Memory:
m          100   0x500003c5 --rw-r--r--     root     root
m           1234 0x500003c6 --rw-r--r--    test      test

我要将Share Memory 下 含有 test的行取出第二列(在 Test Memory 以上)
如何实现?


谢谢!!!

论坛徽章:
0
2 [报告]
发表于 2003-07-13 18:40 |只看该作者

请教文本处理

ipcs -m |awk '/test/{print $2}'

论坛徽章:
0
3 [报告]
发表于 2003-07-14 09:09 |只看该作者

请教文本处理

如果不用 ipcs -m 呢

例如

this is a example
m 100 0x500003c4 --rw-r--r-- root root
m 1234 0x500003c3 --rw-r--r-- test test
m 1235 0x500003c5 --rw-r--r-- test test
this is a test
m 100 0x500003c4 --rw-r--r-- root root
m 1234 0x500003c3 --rw-r--r-- test test

我要将"this is a example " 下含有test行的第二列取出来?

论坛徽章:
0
4 [报告]
发表于 2003-07-14 09:09 |只看该作者

请教文本处理

补充: 在this is test 之上

论坛徽章:
0
5 [报告]
发表于 2003-07-14 13:29 |只看该作者

请教文本处理

有简单的为什么不用?非要那么严谨的话:

  1. #awk script [ test.awk ]
  2. $0!~/.*this is a example test.*/{if(start==0) next}
  3. start==0{start=1;next}
  4. /.*this is a test.*/{exit}
  5. /test/{print $2}
复制代码


  1. $ cat eg
  2. m 2434 0x500003c3 --rw-r--r-- test test
  3. this is a test
  4. this is a example test
  5. m 100 0x500003c4 --rw-r--r-- root root
  6. m 1234 0x500003c3 --rw-r--r-- test test
  7. m 1235 0x500003c5 --rw-r--r-- test test
  8. this is a test
  9. m 100 0x500003c4 --rw-r--r-- root root
  10. m 1234 0x500003c3 --rw-r--r-- test test
  11. $
  12. $
  13. $ awk -f test.awk eg
  14. 1234
  15. 1235
  16. $
复制代码

论坛徽章:
0
6 [报告]
发表于 2003-07-14 14:24 |只看该作者

请教文本处理

sed -n "/this is a example/,/this is a test/p" a3 | grep -v "this is a test"|awk '/test/{print $2}'

results:
1234                                                                           
1235

论坛徽章:
0
7 [报告]
发表于 2003-07-14 14:25 |只看该作者

请教文本处理

the filename is "a3"

论坛徽章:
0
8 [报告]
发表于 2003-07-14 14:35 |只看该作者

请教文本处理

万万分感谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP