【关于 tr 】
时间:2006-01-17 来源:sunyone
不加任何选项,默认为转换操作
例如:把小写转换成大写
# echo aaa BbB | tr '[a-z]' '[A-Z]'
AAA BBB
-s 把重复的字符(包括控制符)压缩成一个字符
AAA BBB
-s 把重复的字符(包括控制符)压缩成一个字符
$ cat 001.txt
And the cowwwwws went homeeeeeeeeeeeee
Or did theyyyyyyyyyyyyy
$ tr -s "[a-z]" < 001.txt
And the cows went home
Or did they 删除空行
And the cowwwwws went homeeeeeeeeeeeee
Or did theyyyyyyyyyyyyy
$ tr -s "[a-z]" < 001.txt
And the cows went home
Or did they 删除空行
$ cat plane.txt
9879932 Spitfire
190992 Lancaster
238991 Typhoon
$ tr -s "[\012]" < plane.txt
9879932 Spitfire
190992 Lancaster
238991 Typhoon -d 删除指定的字符(包括控制符)
9879932 Spitfire
190992 Lancaster
238991 Typhoon
$ tr -s "[\012]" < plane.txt
9879932 Spitfire
190992 Lancaster
238991 Typhoon -d 删除指定的字符(包括控制符)
# cat -v 001.txt
111 aaa
222 bbb
333 ccc
# tr -d '\012' < 001.txt
111 aaa222 bbb333 ccc -c 例如:删除只包含字母或数字的列
111 aaa
222 bbb
333 ccc
# tr -d '\012' < 001.txt
111 aaa222 bbb333 ccc -c 例如:删除只包含字母或数字的列
$ cat diary.txt
mondy 10:50
Tuesday 15:00
wednesday 15:30
thurday 10:30
Fridya 09:20
mondy 10:50
Tuesday 15:00
wednesday 15:30
thurday 10:30
Fridya 09:20
$ tr -cs "[a-z][A-Z]" "\012" <diary.txt
mondy
Tuesday
wednesday
thurday
Fridya
mondy
Tuesday
wednesday
thurday
Fridya
相关阅读 更多 +