免费注册 查看新帖 |

Chinaunix

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

redhat9中的grep怎么不支持-p [复制链接]

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-06-02 21:59 |只看该作者 |倒序浏览
-p的作用是:对于匹配的字符串,显示整个一段,而不是只显示一行。

难道一定要用awk来实现吗?

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
2 [报告]
发表于 2005-06-03 08:21 |只看该作者

redhat9中的grep怎么不支持-p

\n被定义为换行符
那么“换段符”是What?

论坛徽章:
0
3 [报告]
发表于 2005-06-03 08:47 |只看该作者

redhat9中的grep怎么不支持-p

-p[ separator] separator为指定的段分隔符。
缺省的段分隔符是空白行。

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
4 [报告]
发表于 2005-06-03 13:33 |只看该作者

redhat9中的grep怎么不支持-p

举个AIX下的例子吧

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

  7. -q Suppresses all writing to standard output, regardless of matching lines.
  8. Exits with a zero status if an input line is selected. The -q flag with any
  9. combination of the -c, -l and -n flags behaves like the -q flag only.

  10. -s Suppresses error messages ordinarily written for nonexistent or unreadable
  11. files. Other error messages are not suppressed.

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

  18. $
复制代码

论坛徽章:
0
5 [报告]
发表于 2005-06-03 19:03 |只看该作者

redhat9中的grep怎么不支持-p

用perl呀,跨平台的,多好
#perl -n00e 'print if /delimited/' 1

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
6 [报告]
发表于 2005-06-04 12:32 |只看该作者

redhat9中的grep怎么不支持-p

原帖由 "jeff_gu" 发表:
用perl呀,跨平台的,多好
#perl -n00e 'print if /delimited/' 1


看来PERL是挺强的,有必要好好的学习学习

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
7 [报告]
发表于 2006-05-30 14:33 |只看该作者
旧事重提。
想问问,如果用sed或awk能否实现类似功能?

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
8 [报告]
发表于 2006-05-30 14:41 |只看该作者
原帖由 waker 于 2005-6-3 08:21 发表
\n被定义为换行符
那么“换段符”是What?

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
9 [报告]
发表于 2006-05-30 14:50 |只看该作者
awk 'BEGIN{RS="";FS="\n"}
/delimited/ '   1

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
10 [报告]
发表于 2006-05-30 17:34 |只看该作者
谢谢waker,原来awk还可以这样用。不知道sed是不是也可以?
  1. rs6000test:[/etc/security]#grep -p test passwd
  2. test:
  3.         password =
  4.         lastupdate = 1143772773
  5.         flags = ADMCHG

  6. testu5:
  7.         password =
  8.         lastupdate = 1132876926
  9.         flags = ADMCHG

  10. test2:
  11.         password = f2dnL3m5yVSC.
  12.         lastupdate = 1148022485
  13.         flags =

  14. test3:
  15.         password = Dk.ULYzf5wbGU
  16.         lastupdate = 1148026337
  17.         flags =

  18. rs6000test:[/etc/security]#awk 'BEGIN{RS="";ORS="\n\n";FS="\n"} /test/' passwd
  19. test:
  20.         password =
  21.         lastupdate = 1143772773
  22.         flags = ADMCHG

  23. testu5:
  24.         password =
  25.         lastupdate = 1132876926
  26.         flags = ADMCHG

  27. test2:
  28.         password = f2dnL3m5yVSC.
  29.         lastupdate = 1148022485
  30.         flags =

  31. test3:
  32.         password = Dk.ULYzf5wbGU
  33.         lastupdate = 1148026337
  34.         flags =

  35. rs6000test:[/etc/security]#
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP