LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2112|回复: 21

怎样转换以下文档??

[复制链接]
发表于 2003-6-17 18:02:38 | 显示全部楼层 |阅读模式
转换以下文档:

Joey: What, like there's a rule or something?

(The door buzzer sounds and Chandler gets it.)

Chandler: Please don't do that again, it's a horrible sound.

Paul: (over the intercom) It's, uh, it's Paul.

Monica: Oh God, is it 6:30? Buzz him in!

Joey: Who's Paul?

转换成:

{\bf Joey:} What, like there's a rule or something?

(The door buzzer sounds and Chandler gets it.)

{\bf Chandler:} Please don't do that again, it's a horrible sound.

{\bf Paul:} (over the intercom) It's, uh, it's Paul.

{\bf Monica:} Oh God, is it 6:30? Buzz him in!

{\bf Joey:} Who's Paul?

我用:
sed 's/[A-Z]*:/{\\bf & }' $1 > tmp.txt
有的回没有转换.
用:
sed 's/[A-Z].*:/{\\bf & }' $1 > tmp.txt

Monica: Oh God, is it 6:30? Buzz him in!
转成
{\bf Monica: Oh God, is it 6: }30? Buzz him in!

请问怎样才能正确转换??
有些是这样的:
Phoebe, Ross, Chandler, and Joey: Push her down the stairs! Push her down the
stairs! Push her down the stairs!

应该转换成:
{\bf Phoebe, Ross, Chandler, and Joey:} Push her down the stairs! Push her down the
stairs! Push her down the stairs!
发表于 2003-6-17 20:09:14 | 显示全部楼层
#!/usr/bin/perl -w
chomp(@line = <STDIN>);
foreach (@line) {
    s/^(.*[a-zA-Z]/{\\bf $1}/;
    print "$_\n";
}
 楼主| 发表于 2003-6-17 20:50:35 | 显示全部楼层
我的意思是应该匹配第一个字符是大写字母和第一个冒号之间在内容.
 楼主| 发表于 2003-6-17 20:53:34 | 显示全部楼层
因为你不知道第二个冒号前的字符是什么.
发表于 2003-6-17 21:49:13 | 显示全部楼层
我的意思是应该匹配第一个字符是大写字母和第一个冒号之间在内容.

这并不能保证所有的匹配都正确,例如对下面的句子
The door opened at 6:30 this morning.

从这篇文章来看,是一篇对话录,你应该是希望将所有发言者的姓名加粗显示,我想上面的脚本应该可以达到这个要求。
 楼主| 发表于 2003-6-17 23:13:23 | 显示全部楼层
我试试.
发表于 2003-6-18 00:12:24 | 显示全部楼层
try it ;)
[javalee//home/javalee/myshell]sed 's/\(.*[a-z][:]\)/{\\bf \1}/g' urfile
{\bf Joey:} What, like there's a rule or something?

(The door buzzer sounds and Chandler gets it.)

{\bf Chandler:} Please don't do that again, it's a horrible sound.

{\bf Paul:} (over the intercom) It's, uh, it's Paul.

{\bf Monica:} Oh God, is it 6:30? Buzz him in!

{\bf Joey:} Who's Paul?
 楼主| 发表于 2003-6-21 00:30:28 | 显示全部楼层
\1 是匹配的次数吗??
 楼主| 发表于 2003-6-21 00:35:11 | 显示全部楼层
sed 's/^[A-Z].*[a-zA-Z]:/{\\style \1}'
会好一点吧??
奇怪的是,开头是小写的也匹配了.
它怎么忽略了???
 楼主| 发表于 2003-6-21 00:36:49 | 显示全部楼层
我不会用perl.呵呵.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表