linux之shell 其他

liqilin0429發表於2011-01-24

 去除重複出現的字元
oracle@ser168:~/qilin/demo> cat oops.txt
And the cowwwwws went homeeeeeeeeeeeeeeeeeeeeeeeee
Or did theYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
oracle@ser168:~/qilin/demo> tr -s "[a-z],[A-Z]"And the cows went home
Or did theY
 刪除空行
oracle@ser168:~/qilin/demo> cat plane.txt
kfalfkafa sdfadfa


dfaflakfalf liqilin

43314141 zhuauang

fdafaflaf  dfafkalf

5422422  li
oracle@ser168:~/qilin/demo> tr -s "[\012]" kfalfkafa sdfadfa
dfaflakfalf liqilin
43314141 zhuauang
fdafaflaf  dfafkalf
5422422  li

oracle@ser168:~/qilin/demo> tr -s ["\n"] kfalfkafa sdfadfa
dfaflakfalf liqilin
43314141 zhuauang
fdafaflaf  dfafkalf
5422422  li

 大寫到小寫
oracle@ser168:~/qilin/demo> cat oops.txt
And the cowwwwws went homeeeeeeeeeeeeeeeeeeeeeeeee
Or did theYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
oracle@ser168:~/qilin/demo> cat oops.txt | tr "[A-Z]" "[a-z]" >lower_oopst.txt
oracle@ser168:~/qilin/demo> cat lower_oopst.txt
and the cowwwwws went homeeeeeeeeeeeeeeeeeeeeeeeee
or did theyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
小寫到大寫
oracle@ser168:~/qilin/demo> cat oops.txt
And the cowwwwws went homeeeeeeeeeeeeeeeeeeeeeeeee
Or did theYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
oracle@ser168:~/qilin/demo> cat oops.txt | tr "[a-z]" "[A-Z]" >upper_oopst.txt
oracle@ser168:~/qilin/demo> cat upper_oopst.txt
AND THE COWWWWWS WENT HOMEEEEEEEEEEEEEEEEEEEEEEEEE
OR DID THEYYYYYYYYYYYYYYYYYYYYYYYYYYYYY

 刪除指定字元
oracle@ser168:~/qilin/demo> cat diary.txt
monday 10:50
Tuserday 15:50
wednesday 12;30
THURDAY 10;20
Friday 06:34
oracle@ser168:~/qilin/demo> tr -cs "[a-z][A-Z]" "[\012*]" monday
Tuserday
wednesday
THURDAY
Friday
 轉換控制字元

 去除重複出現的字元
oracle@ser168:~/qilin/demo> cat oops.txt
And the cowwwwws went homeeeeeeeeeeeeeeeeeeeeeeeee
Or did theYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
oracle@ser168:~/qilin/demo> tr -s "[a-z],[A-Z]"And the cows went home
Or did theY
 刪除空行
oracle@ser168:~/qilin/demo> cat plane.txt
kfalfkafa sdfadfa


dfaflakfalf liqilin

43314141 zhuauang

fdafaflaf  dfafkalf

5422422  li
oracle@ser168:~/qilin/demo> tr -s "[\012]" kfalfkafa sdfadfa
dfaflakfalf liqilin
43314141 zhuauang
fdafaflaf  dfafkalf
5422422  li

oracle@ser168:~/qilin/demo> tr -s ["\n"] kfalfkafa sdfadfa
dfaflakfalf liqilin
43314141 zhuauang
fdafaflaf  dfafkalf
5422422  li

 大寫到小寫
oracle@ser168:~/qilin/demo> cat oops.txt
And the cowwwwws went homeeeeeeeeeeeeeeeeeeeeeeeee
Or did theYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
oracle@ser168:~/qilin/demo> cat oops.txt | tr "[A-Z]" "[a-z]" >lower_oopst.txt
oracle@ser168:~/qilin/demo> cat lower_oopst.txt
and the cowwwwws went homeeeeeeeeeeeeeeeeeeeeeeeee
or did theyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
小寫到大寫
oracle@ser168:~/qilin/demo> cat oops.txt
And the cowwwwws went homeeeeeeeeeeeeeeeeeeeeeeeee
Or did theYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
oracle@ser168:~/qilin/demo> cat oops.txt | tr "[a-z]" "[A-Z]" >upper_oopst.txt
oracle@ser168:~/qilin/demo> cat upper_oopst.txt
AND THE COWWWWWS WENT HOMEEEEEEEEEEEEEEEEEEEEEEEEE
OR DID THEYYYYYYYYYYYYYYYYYYYYYYYYYYYYY

 刪除指定字元
oracle@ser168:~/qilin/demo> cat diary.txt
monday 10:50
Tuserday 15:50
wednesday 12;30
THURDAY 10;20
Friday 06:34
oracle@ser168:~/qilin/demo> tr -cs "[a-z][A-Z]" "[\012*]" monday
Tuserday
wednesday
THURDAY
Friday
 轉換控制字元

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20976446/viewspace-684542/,如需轉載,請註明出處,否則將追究法律責任。

相關文章