免费注册 查看新帖 |

Chinaunix

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

一个正则表达式 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2009-07-11 18:44 |只看该作者
多谢9楼,非常感谢找来这么好的资料。。。

论坛徽章:
2
丑牛
日期:2014-06-11 13:55:04ChinaUnix元老
日期:2015-02-06 15:16:14
12 [报告]
发表于 2009-07-11 18:45 |只看该作者

回复 #8 zngell 的帖子

s/regular expression/replacement/flags
     ____________________________________________________________
                  Substitute   the   replacement   string    for
                  instances  of  the  regular  expression in the
                  pattern  space.   Any  character  other   than
                  backslash  or newline can be used instead of a
                  slash to delimit the RE and  the  replacement.
                  Within the RE and the replacement, the RE del-
                  imiter itself can be used as a literal charac-
                  ter if it is preceded by a backslash.
     ____________________________________________________________
                  An ampersand (&) appearing in the  replacement
                  will  be  replaced  by the string matching the
                  RE.  The special meaning of & in this  context
                  can   be   suppressed   by   preceding  it  by
                  backslash.  The characters \n, where  n  is  a
                  digit, will be replaced by the text matched by
                  the  corresponding  backreference  expression.
                  For each backslash (\) encountered in scanning
                  replacement from beginning to end, the follow-
                  ing  character  loses  its special meaning (if
                  any).  It is unspecified what special  meaning
                  is  given  to any character other than &, \ or
                  digits.
     ____________________________________________________________
                  A line can be split by substituting a  NEWLINE
                  character   into  it.   The  application  must
                  escape the NEWLINE character in  the  replace-
                  ment  by  preceding it with backslash.  A sub-
                  stitution is considered to have been performed
                  even if the replacement string is identical to
                  the string that it replaces.
     ____________________________________________________________

                            flags is zero or more of:
     ____________________________________________________________
                  n n= 1 - 512.  Substitute for  just  the   nth
                  occurrence of the regular expression.
     ____________________________________________________________
                  g Global.  Substitute for  all  nonoverlapping
                  instances  of  the  regular  expression rather
                  than just the first one.  If both g and n  are
                  specified, the results are unspecified.



我给你摘出来了,不用我翻译吧?

man sed的

[ 本帖最后由 山野村夫 于 2009-7-14 14:23 编辑 ]

论坛徽章:
0
13 [报告]
发表于 2009-07-11 18:45 |只看该作者

回复 #10 zngell 的帖子

就是将你前面匹配的那个内容替换成空

论坛徽章:
2
丑牛
日期:2014-06-11 13:55:04ChinaUnix元老
日期:2015-02-06 15:16:14
14 [报告]
发表于 2009-07-11 18:46 |只看该作者
原帖由 zngell 于 2009-7-11 18:44 发表


你说的也只是/g 不是//g 啊?

s/a/b/g
这里b可以为空

论坛徽章:
0
15 [报告]
发表于 2009-07-11 18:50 |只看该作者
原帖由 山野村夫 于 2009-7-11 18:46 发表

s/a/b/g
这里b可以为空


茅塞顿开 哈哈哈。。多谢和尚,哪天我找位师太回报您的大恩大德~~~~

论坛徽章:
2
丑牛
日期:2014-06-11 13:55:04ChinaUnix元老
日期:2015-02-06 15:16:14
16 [报告]
发表于 2009-07-11 18:52 |只看该作者

回复 #15 zngell 的帖子

呵呵,你那个g的理解有误,见我12楼的回复

论坛徽章:
0
17 [报告]
发表于 2009-07-11 18:58 |只看该作者
原帖由 山野村夫 于 2009-7-11 18:52 发表
呵呵,你那个g的理解有误,见我12楼的回复


呵呵,收到。

论坛徽章:
0
18 [报告]
发表于 2009-07-11 23:08 |只看该作者

回复 #1 zngell 的帖子

这个有点眼熟…… 鸟哥的例题??

论坛徽章:
0
19 [报告]
发表于 2009-07-14 14:20 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
20 [报告]
发表于 2009-07-14 14:35 |只看该作者

回复 #8 zngell 的帖子

中间有|隔开的两个sed指令
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP