免费注册 查看新帖 |

Chinaunix

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

[文本处理] sed & awk 的一个sed 问题的困惑。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-07-29 10:21 |只看该作者 |倒序浏览
原始题目:
  1. I want to see @f1(what will happen) if we put the
  2. font change commands @f1(on a set of lines). If I
  3. understand
  4. things (correctly), the @f1(third) line causes problems.
  5. (No?).
  6. Is this really the case, or is it (maybe) just something
  7. else?
  8. Let's test having two on a line @f1(here) and @f1(there) as
  9. well as one that begins on one line and ends @f1(somewhere
  10. on another line). What if @f1(it is here) on the line?
  11. Another @f1(one).
复制代码
要求把 @f1(内容) 变成\fb内容\fr
如果做练习,作者的这个东东是对的:
  1. # Scribe font change script.
  2. s/@f1(\([^)]*\))/\\fB\1\\fR/g
  3. /@f1(.*/{
  4. N
  5. s/@f1(\(.*\n[^)]*\))/\\fB\1\\fR/g
  6. P
  7. D
  8. }
复制代码
那么,如果在文本的well as one that begins on one line and ends @f1(somewhere之后在插入一行内容,你怎么做到替换成功? 如果这行之前还有@f1()是不是就无解,只能用交互式的进行?

论坛徽章:
3
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:51:162015年亚洲杯之阿曼
日期:2015-04-07 20:00:59
2 [报告]
发表于 2012-07-29 10:51 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
3 [报告]
发表于 2012-07-29 11:55 |只看该作者
@()可能嵌套么?

论坛徽章:
0
4 [报告]
发表于 2012-07-29 14:02 |只看该作者
回复 3# hbmhalley


    嵌套的问题先不考虑。

论坛徽章:
0
5 [报告]
发表于 2012-07-29 14:24 |只看该作者
回复 1# wuxiaobo_2009


本书后边提到了这个问题郁闷,贴出来:
# Scribe font change script. New and Improved.
:begin
/@f1(\([^)]*\))/{
s//\\fB\1\\fR/g
b begin
}
/@f1(.*/{
N
s/@f1(\([^)]*\n[^)]*\))/\\fB\1\\fR/g
t again
b begin
}
:again
P
D



   

论坛徽章:
0
6 [报告]
发表于 2012-07-29 17:02 |只看该作者
本帖最后由 hbmhalley 于 2012-07-29 17:03 编辑

  1. :1
  2. s/@f1(\([^)]*\))/\\fB\1\\fR/g
  3. /@f1(/!b
  4. s//\\fB/
  5. :2 n;/)/!b2
  6. s//\\fR/;b1
复制代码
要是没嵌套括号的话

论坛徽章:
0
7 [报告]
发表于 2012-07-29 21:02 |只看该作者
真他妈的高深
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP