LinuxSir.cn,穿越时空的Linuxsir!

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

我想把下面的人名改成第一个字母大字,其它小写

[复制链接]
发表于 2003-6-23 12:56:59 | 显示全部楼层 |阅读模式
我想把下面的人名改成第一个字母大字,其它小写,
用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.
发表于 2003-6-23 15:25:24 | 显示全部楼层
挺好玩的,这个还是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.
发表于 2003-6-23 16:16:52 | 显示全部楼层
处理文本是awk的强项!,还得努力学习呀~~~
 楼主| 发表于 2003-6-23 16:55:24 | 显示全部楼层
Oooooooooo!Nooooooooooooooooo!
我刚用c语言搞掂,没想到.........
痛苦之中!!!!!!!
sed学到此为止了.(用它处理最简单的就可以了)
 楼主| 发表于 2003-6-23 17:08:39 | 显示全部楼层
呵呵.谢谢二位.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;
}
 楼主| 发表于 2003-6-23 17:22:01 | 显示全部楼层
缩进不见了?????????

不过还是我的好一点.因为有时会 n 个人一起说话的.(sorry 我没有说清楚)
发表于 2003-6-23 17:25:47 | 显示全部楼层
hehe,这个也太麻烦了
我看到题目的第一反映是逐行读,然后cut->tr,最后拼回去,大概和你的思路差不多,直接sed可能也行,它有些很少用的命令,比如x, h, H,t什么的,可以操作得到的pattern,但是我也不熟。

最后man awk, 搜了一下lower,搞定

perl的格言: TMTOWTDI(tim-today~)
 楼主| 发表于 2003-6-23 22:23:48 | 显示全部楼层
我试过用h,H,g,G,但发现太烦了,不如c来的方便,想都不用想就编出来了.
 楼主| 发表于 2003-6-23 22:27:42 | 显示全部楼层
我试过用h,H,g,G,但发现太烦了,不如c来的方便,想都不用想就编出来了.

我不明白的是,sed好象不怎么注意大小写.
发表于 2003-6-24 00:41:17 | 显示全部楼层
我用sed怎么也弄不出来!...头都大啦~~~!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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