|
|
第 1 帖 | |
|
|
标题: 我想把下面的人名改成第一个字母大字,其它小写 我想把下面的人名改成第一个字母大字,其它小写,
用sed,tr怎么弄???谢谢. {\bf MONICA:} Maye it's me. {\bf ROSS:} Don't be silly. Ben loves you. He's just being Mr. Crankypants. {\bf CHANDLER:} You know, I once dated a Miss Crankypants. Lovely girl, kinda moody. {\bf ROSS:} There we go. All better. (gives Ben back to Monica) {\bf MONICA:} There's my little boy. (Ben starts crying again) {\bf CHANDLER:} Can I uh see something? (Takes Ben. When he puts him close to Monica, Ben cries. When he moves Ben away, he stops crying.) {\bf JOEY:} Cool. {\bf MONICA:} He hates me. My nephew hates me. |
|
|
|
|
|
|
|
第 2 帖 | |
|
|
挺好玩的,这个还是awk版本
一行搞定$cat rawdata.3 | awk 'BEGIN {FS=":}"} {if ($1!="") {print substr($1,1,6)tolower(substr($1,7))":}"$2} else {print $0}}' {\bf Monica:} Maye it's me. {\bf Ross:} Don't be silly. Ben loves you. He's just being Mr. Crankypants. {\bf Chandler:} You know, I once dated a Miss Crankypants. Lovely girl, kinda moody. {\bf Ross:} There we go. All better. (gives Ben back to Monica) {\bf Monica:} There's my little boy. (Ben starts crying again) {\bf Chandler:} Can I uh see something? (Takes Ben. When he puts him close to Monica, Ben cries. When he moves Ben away, he stops crying.) {\bf Joey:} Cool. {\bf Monica:} He hates me. My nephew hates me.
__________________
E6300@3.2G/P5B-D WiFi/2G RAM/1TB HDD/3540A/7900GT/E-MU 0404 Logitech S 510/MX Revolution/2407WFP/LaserJet 1020 go wild, go Gentoo |
|
|
|
|
|
|
|
第 3 帖 | |
|
|
处理文本是awk的强项!,还得努力学习呀~~~
![]() |
|
|
|
|
|
|
|
第 4 帖 | |
|
|
Oooooooooo!Nooooooooooooooooo!
我刚用c语言搞掂,没想到......... 痛苦之中!!!!!!! sed学到此为止了.(用它处理最简单的就可以了)
__________________
Kurt is me. Studing hard. Making my way to the top of the world. |
|
|
|
|
|
|
|
第 5 帖 | |
|
|
呵呵.谢谢二位.c 可不方便处理这样的小事!
///////////////////////////// #include<stdio.h> #include<string.h> int main(){ char ch; int count=0; while((ch=getchar())!=EOF){ if(ch==' '){count=0;} if(isalpha(ch)){count++; if(count==1)putchar(ch); else putchar(tolower(ch)); }else putchar(ch); if(ch==':')do { ch=getchar(); putchar(ch); }while(ch!='\n'&&ch!=EOF); } return 0; } |
|
|
|
|
|
|
|
第 6 帖 | |
|
|
缩进不见了?????????
不过还是我的好一点.因为有时会 n 个人一起说话的.(sorry 我没有说清楚) |
|
|
|
|
|
|
|
第 7 帖 | |
|
|
hehe,这个也太麻烦了
我看到题目的第一反映是逐行读,然后cut->tr,最后拼回去,大概和你的思路差不多,直接sed可能也行,它有些很少用的命令,比如x, h, H,t什么的,可以操作得到的pattern,但是我也不熟。 最后man awk, 搜了一下lower,搞定 ![]() perl的格言: TMTOWTDI(tim-today~) |
|
|
|
|
|
|
|
第 8 帖 | |
|
|
我试过用h,H,g,G,但发现太烦了,不如c来的方便,想都不用想就编出来了.
|
|
|
|
|
|
|
|
第 9 帖 | |
|
|
我试过用h,H,g,G,但发现太烦了,不如c来的方便,想都不用想就编出来了.
我不明白的是,sed好象不怎么注意大小写. |
|
|
|
|
|
|
|
第 10 帖 | |
|
|
我用sed怎么也弄不出来!:(...头都大啦~~~!!!
|
|
|
|
|
|
|
|
第 11 帖 | |
|
|
标题: 我也来个perl版的 #!/usr/bin/perl -w
while (<>) { s/{\\bf (\w+):}/{\\bf \u\L$1:}/; print; } 不过只能处理单人名,如果{}中有多个人名,没想出什么好办法一句话搞定,只能象lordbyorn那样写个循环,还有一种方法是对人名进行全局替换,呵呵,这方法土了点。 ![]()
__________________
http://211.92.88.40/~lyoo/bookmark/bookmark.html |
|
|
|
|
|
|
|
第 12 帖 | |
|
|
《sed & awk》里有sed例子(很头大的,只能处理一个人名)。
人名太多. 《friends》的剧本弄好了,可以打印了,(找个2毛一张的来,呵呵,,,,,,,,) 谢谢各位。 请问,我的名字能不能改??(lordbyorn是笔误,应该是Lord Byron,还想做个漂亮的,其实Lord Kurt才是我的英文名) |
|
|
|
|
|
|
|
第 13 帖 | |
|
|
如果能够对文章中的每个word进行处理的话是很简单的。
可是sed是对句子处理的。 |
|
|
|
|
|
|
|
第 14 帖 | |
|
|
是啊,sed是基于行的
我觉得用vi的script应该也行,可惜我不会 btw,多人名是什么样子的? {\bf MARRY ROSE MIKE} ? |
|
|
|
|
|
|
|
第 15 帖 | |
|
|
Ross, Chandler, and Joey: Push her down the stairs! Push her down the stairs! Push her down the stairs!
{\style }是我加的。因为用latex.大小写是不定的,主要是作者喜欢。(人名第一个字母肯定大写) |
|
|
|
|
|