免费注册 查看新帖 |

Chinaunix

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

[新手入门] aix grep -p 的用法!!-在线等求助!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-05-31 16:40 |只看该作者 |倒序浏览
本帖最后由 luck_libiao 于 2012-05-31 16:41 编辑

如何设置段落分隔符!如文件如下:a.txt
root
hello
1
2
3
4
root
hi
root
kk
root
pp
root
cc
想要的是包含hello 的以root 做为段分隔符的中间的部分:
hello
1
2
3
4
而这个文件非常的大,大约有1G左右,直接vi是无法打开的,会提示内存不足存放该文件.
所以目前想通过grep -p 来做,但是由于grep -p 默认是返回以空行为段落分隔符的,所以这样查找无法返回正确的结果!
请教各位大虾,有何见解!any suggestion is welcome!

论坛徽章:
0
2 [报告]
发表于 2012-05-31 16:53 |只看该作者
回复 1# luck_libiao
顶下


   

论坛徽章:
0
3 [报告]
发表于 2012-05-31 17:01 |只看该作者
grep -v "root" a.txt

论坛徽章:
0
4 [报告]
发表于 2012-05-31 18:21 |只看该作者
回复 3# 346279055


grep -v "root" 只是把不包含root 的打印出来,我要的结果是一个段落,不是全部!
root做为分割!
   

论坛徽章:
0
5 [报告]
发表于 2012-05-31 20:06 |只看该作者
grep -n "root" a.txt   
grep -n "hello" a.txt
查看root和hello所在的行数为x和y
sed -n 'x,yp' a.txt >  b.txt

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
6 [报告]
发表于 2012-06-01 09:09 |只看该作者
没环境,没法试

grep -p是可以自定义分隔的,你man grep看看

论坛徽章:
0
7 [报告]
发表于 2012-06-05 11:45 |只看该作者
回复 6# yddll


      -p[Separator]
            Displays the entire paragraph containing matched lines. Paragraphs are delimited by paragraph separators, as specified
            by the Separator parameter, which are patterns in the same form as the search pattern. Lines containing the paragraph
            separators are used only as separators; they are never included in the output. The default paragraph separator is a
            blank line.

现在设置-p[root]
结果无法查询到:
vi a.txt
"a.txt" [New file]
root
hello
1
2
3
4
root
hi
root
kk
root
pp
root
cc
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"a.txt" [New file] 14 lines, 51 characters
<51 CESHIBMP [bmp] :/enip/bmp/userfile/libiao/test>grep -p[root] a.txt
No match.

论坛徽章:
0
8 [报告]
发表于 2012-06-05 11:46 |只看该作者
回复 5# 346279055


    大哥,这个里面又不是只有1个hello的,有很多的,你怎么办?

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
9 [报告]
发表于 2012-06-05 20:14 |只看该作者
  1. -bash-3.00$ grep -p^root$ hello oooopuuu
  2. hello
  3. 1
  4. 2
  5. 3
  6. 4

  7. -bash-3.00$ more oooopuuu
  8. root
  9. hello
  10. 1
  11. 2
  12. 3
  13. 4
  14. root
  15. hi
  16. root
  17. kk
  18. root
  19. pp
  20. root
  21. cc
复制代码

论坛徽章:
2
午马
日期:2015-01-27 11:22:392015年辞旧岁徽章
日期:2015-03-03 16:54:15
10 [报告]
发表于 2012-06-05 23:58 |只看该作者
回复 1# luck_libiao


    1G大的文件都打不开啊.....这系统还装什么AIX....
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP