Saturday, September 25, 2010

Linux大小寫轉換方法

以下以小写转大写为例
(1)sed:
cat file | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'

(2)tr:
cat file | tr a-z A-Z
cat file | tr "[:lower:]" "[:upper:]"

(3)perl:
$string="abcdef";
$string =~ tr/[a-z]/[A-Z]/;
or
$string=uc($string); #大小转小写用lc,具体参见perldoc -f lc与perdoc -f uc

參考來源:

"以下以小写转大写为例 (1)sed: cat file | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'   (2)tr: cat file | tr a-z A-Z cat file | tr "[:lower:]" "[:upper:]"   (3)perl: $string="abcdef"; $string =~ tr/[a-z]/[A-Z]/; or $string=uc($string); #大小转小写用lc,具体参见perldoc -f lc与perdoc -f uc"
- Linux下大小写转换的方法小结 - TIPs - 冷月无声 (在「Google 網頁註解」中檢視)

No comments: