- 论坛徽章:
- 0
|
[root@localhost ch09]# more capsformatch
awk '#lower
BEGIN{
upper ="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lower ="abcdefghijklmnopqrstuvwxyz"
}
#for all lines
{
while(match($0,/[A-Z]+/))
for(x=RSTART;x<RSTART+RLENGTH;++x){
CAP = substr($0,x,1) #取得要处理的行里的大写字母
CHAR = index(upper,CAP) #取得大写字母在upper字符串里面的位置数字,应该是最左边从1开始数。
gsub(CAP,substr(lower,CHAR,1)) #取得和upper字符串里和lower里相同位置的小写字母,全部替换。
}
print $0
}' $*
运行以后出现问题:
- [root@localhost ch09]# more test
- Every NOW and then, a WORD I type appears in CAPS.
- [root@localhost ch09]# ./capsformatch test
- aaaaa aaa aaa aaaa, a aaaa a aaaa aaaaaaa aa aaaa.
- [root@localhost ch09]# more test2
- Root and
- [root@localhost ch09]# ./capsformatch test2
- aaaa aaa
复制代码
请教各位!
谢谢! |
|