使用tr的-s选项去除重复出现的字符:
[oracle@localhost tr.folder]$ cat oops.txt
And the cowwwwwws went homeeeee
Or did theyyyyyyyyyyyyy
[oracle@localhost tr.folder]$ tr -s "[a-z]" < oops.txt
And the cows went home
Or did they
删除空行:
[oracle@localhost tr.folder]$ cat oops.txt
And the cowwwwwws went homeeeee
Or did theyyyyyyyyyyyyy
fas ods css
[oracle@localhost tr.folder]$ tr -s "[\012]" < oops.txt
And the cowwwwwws went homeeeee
Or did theyyyyyyyyyyyyy
fas ods css
转换大小写:
[oracle@localhost tr.folder]$ echo "hello today is a Fine DAY" | tr "[a-z]" "[A-Z]"
HELLO TODAY IS A FINE DAY
删除数字:
[oracle@localhost tr.folder]$ cat oops.txt
And the cowwwwwws went homeeeee
23
3123asadfas
123ffff
Or did theyyyyyyyyyyyyy
12
fas ods css
[oracle@localhost tr.folder]$ tr -cs "[a-z][A-Z]" "[\012*]" < oops.txt
And
the
cowwwwwws
went
homeeeee
asadfas
ffff
Or
did
theyyyyyyyyyyyyy
fas
ods
css
[oracle@localhost etc]$ echo "`who | wc -l` users are on today"
2 users are on today
设置变量的默认值:
[oracle@localhost testDir]$ day=bad
[oracle@localhost testDir]$ echo "today is a ${day:-fine} day"
today is a bad day
[oracle@localhost testDir]$ unset day
[oracle@localhost testDir]$ echo "today is a ${day:-fine} day"
today is a fine day