LinuxSir.Org  
| 网站首页 | 注册账号 | 论坛帮助 |

欢迎来到LinuxSir.Org!
您还未登录,请登录后查看论坛,或者点击论坛上方的注册链接注册新账号。


发表新主题 回复
精华主题  
主题工具
旧 03-06-23, 12:56 第 1 帖
lordbyorn
 
lordbyorn 的头像
 
 
临时退役版主  
  注册日期: May 2003
  帖子: 889
  精华: 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.
  lordbyorn 当前离线   回复时引用此帖
旧 03-06-23, 15:25 第 2 帖
lucida
 
 
 
注册会员  
  注册日期: Oct 2002
  我的住址: .:DRL:.
  帖子: 2,492
  精华: 9
 

挺好玩的,这个还是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
  lucida 当前离线   回复时引用此帖
旧 03-06-23, 16:16 第 3 帖
KornLee
 
 
 
★☆★☆★☆★  
  注册日期: Nov 2002
  我的住址: LinuxWorld
  帖子: 6,960
  精华: 61
 

处理文本是awk的强项!,还得努力学习呀~~~
  KornLee 当前离线   回复时引用此帖
旧 03-06-23, 16:55 第 4 帖
lordbyorn
 
lordbyorn 的头像
 
 
临时退役版主  
  注册日期: May 2003
  帖子: 889
  精华: 1
 

Oooooooooo!Nooooooooooooooooo!
我刚用c语言搞掂,没想到.........
痛苦之中!!!!!!!
sed学到此为止了.(用它处理最简单的就可以了)







__________________
Kurt is me.
Studing hard. Making my way to the top of the world.
  lordbyorn 当前离线   回复时引用此帖
旧 03-06-23, 17:08 第 5 帖
lordbyorn
 
lordbyorn 的头像
 
 
临时退役版主  
  注册日期: May 2003
  帖子: 889
  精华: 1
 

呵呵.谢谢二位.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;
}
  lordbyorn 当前离线   回复时引用此帖
旧 03-06-23, 17:22 第 6 帖
lordbyorn
 
lordbyorn 的头像
 
 
临时退役版主  
  注册日期: May 2003
  帖子: 889
  精华: 1
 

缩进不见了?????????

不过还是我的好一点.因为有时会 n 个人一起说话的.(sorry 我没有说清楚)
  lordbyorn 当前离线   回复时引用此帖
旧 03-06-23, 17:25 第 7 帖
lucida
 
 
 
注册会员  
  注册日期: Oct 2002
  我的住址: .:DRL:.
  帖子: 2,492
  精华: 9
 

hehe,这个也太麻烦了
我看到题目的第一反映是逐行读,然后cut->tr,最后拼回去,大概和你的思路差不多,直接sed可能也行,它有些很少用的命令,比如x, h, H,t什么的,可以操作得到的pattern,但是我也不熟。

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

perl的格言: TMTOWTDI(tim-today~)
  lucida 当前离线   回复时引用此帖
旧 03-06-23, 22:23 第 8 帖
lordbyorn
 
lordbyorn 的头像
 
 
临时退役版主  
  注册日期: May 2003
  帖子: 889
  精华: 1
 

我试过用h,H,g,G,但发现太烦了,不如c来的方便,想都不用想就编出来了.
  lordbyorn 当前离线   回复时引用此帖
旧 03-06-23, 22:27 第 9 帖
lordbyorn
 
lordbyorn 的头像
 
 
临时退役版主  
  注册日期: May 2003
  帖子: 889
  精华: 1
 

我试过用h,H,g,G,但发现太烦了,不如c来的方便,想都不用想就编出来了.

我不明白的是,sed好象不怎么注意大小写.
  lordbyorn 当前离线   回复时引用此帖
旧 03-06-24, 00:41 第 10 帖
KornLee
 
 
 
★☆★☆★☆★  
  注册日期: Nov 2002
  我的住址: LinuxWorld
  帖子: 6,960
  精华: 61
 

我用sed怎么也弄不出来!:(...头都大啦~~~!!!
  KornLee 当前离线   回复时引用此帖
旧 03-06-24, 11:55 第 11 帖
LYOO
 
LYOO 的头像
 
 
注册会员  
  注册日期: Jan 2003
  帖子: 782
  精华: 37
 

标题: 我也来个perl版的


#!/usr/bin/perl -w
while (<>) {
s/{\\bf (\w+):}/{\\bf \u\L$1:}/;
print;
}

不过只能处理单人名,如果{}中有多个人名,没想出什么好办法一句话搞定,只能象lordbyorn那样写个循环,还有一种方法是对人名进行全局替换,呵呵,这方法土了点。







__________________
http://211.92.88.40/~lyoo/bookmark/bookmark.html
  LYOO 当前离线   回复时引用此帖
旧 03-06-24, 12:27 第 12 帖
lordbyorn
 
lordbyorn 的头像
 
 
临时退役版主  
  注册日期: May 2003
  帖子: 889
  精华: 1
 

《sed & awk》里有sed例子(很头大的,只能处理一个人名)。

人名太多.

《friends》的剧本弄好了,可以打印了,(找个2毛一张的来,呵呵,,,,,,,,)

谢谢各位。

请问,我的名字能不能改??(lordbyorn是笔误,应该是Lord Byron,还想做个漂亮的,其实Lord Kurt才是我的英文名)
  lordbyorn 当前离线   回复时引用此帖
旧 03-06-24, 12:39 第 13 帖
lordbyorn
 
lordbyorn 的头像
 
 
临时退役版主  
  注册日期: May 2003
  帖子: 889
  精华: 1
 

如果能够对文章中的每个word进行处理的话是很简单的。
可是sed是对句子处理的。
  lordbyorn 当前离线   回复时引用此帖
旧 03-06-24, 12:59 第 14 帖
lucida
 
 
 
注册会员  
  注册日期: Oct 2002
  我的住址: .:DRL:.
  帖子: 2,492
  精华: 9
 

是啊,sed是基于行的
我觉得用vi的script应该也行,可惜我不会

btw,多人名是什么样子的?
{\bf MARRY ROSE MIKE} ?
  lucida 当前离线   回复时引用此帖
旧 03-06-24, 15:25 第 15 帖
lordbyorn
 
lordbyorn 的头像
 
 
临时退役版主  
  注册日期: May 2003
  帖子: 889
  精华: 1
 

Ross, Chandler, and Joey: Push her down the stairs! Push her down the stairs! Push her down the stairs!

{\style }是我加的。因为用latex.大小写是不定的,主要是作者喜欢。(人名第一个字母肯定大写)
  lordbyorn 当前离线   回复时引用此帖
发表新主题 回复


主题工具

发帖规则
您 [不可以] 发表新主题
您 [不可以] 回复主题
您 [不可以] 上传附件
您 [不可以] 编辑您的帖子

已 [启用] BB 代码
已 [启用] 表情符号
已 [启用] IMG 代码
已 [禁用] HTML 代码
[论坛跳转…]


所有时间均为[北京时间]。现在的时间是 13:13


Powered by vBulletin 版本 3.6.8
版权所有 ©2000 - 2010, Jelsoft Enterprises Ltd.
官方中文技术支持: vBulletin 中文
版权所有 ©2002 - 2009, LinuxSir.Org