shell大小写字母转换
2008-05-07 10:25
#!/bin/sh
#----------------------------------------------------------
# [:upper:] [ A - Z ]
# [:lower:] [ a - z ]
# [:digit:] [ 0 - 9 ]
# [:alnum:] [ 0 - 9 a - z A-Z]
# [:space:] 空格或t a b键
# [:alpha:] [ a - z A - Z ]
#----------------------------------------------------------
# tr
for f in *
do
mv $f `echo $f | tr "[:upper:]" "[:lower:]" `
done
#awk
#把当前目录下的所有小写文件名都改为大写文件名。
ls | awk '{printf("mv %s %s\n", $0, toupper($0))|"sh"}'
#把当前目录下的所有大写文件名都改为小写文件名。
ls | awk '{printf("mv %s %s\n", $0, tolower($0))|"sh"}'
#sed
cat file | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
2008-05-07 10:25
#!/bin/sh
#----------------------------------------------------------
# [:upper:] [ A - Z ]
# [:lower:] [ a - z ]
# [:digit:] [ 0 - 9 ]
# [:alnum:] [ 0 - 9 a - z A-Z]
# [:space:] 空格或t a b键
# [:alpha:] [ a - z A - Z ]
#----------------------------------------------------------
# tr
for f in *
do
mv $f `echo $f | tr "[:upper:]" "[:lower:]" `
done
#awk
#把当前目录下的所有小写文件名都改为大写文件名。
ls | awk '{printf("mv %s %s\n", $0, toupper($0))|"sh"}'
#把当前目录下的所有大写文件名都改为小写文件名。
ls | awk '{printf("mv %s %s\n", $0, tolower($0))|"sh"}'
#sed
cat file | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'