分类: LINUX
2009-02-20 17:45:31
下面讲述:
引用: |
• 大小写转换。 • 去除控制字符。 • 删除空行。 |
代码: |
t r - c - d - s [ " s t r i n g 1 _ t o _ t r a n s l a t e _ f r o m " ] [ " s t r i n g 2 _ t o _ t r a n s l a t e _ t o " ] i n p u t _f i l e |
引用: |
-c 用字符串1中字符集的补集替换此字符集,要求字符集为A S C I I。 -d 删除字符串1中所有输入字符。 -s 删除所有重复出现字符序列,只保留第一个;即将重复出现字符串压缩为一个字符串。 |
引用: |
[a-z] a-z内的字符组成的字符串。 [A-Z] A-Z内的字符组成的字符串。 [0-9] 数字串。 /octal 一个三位的八进制数,对应有效的A S C I I字符。 [O*n] 表示字符O重复出现指定次数n。因此[ O * 2 ]匹配O O的字符串。 大部分t r变种支持字符类和速记控制字符。 字符类格式为[:c l a s s ],包含数字、希腊字母、空行、小写、大写、c n t r l键、空格、点记符、图形等等。 |
代码: |
速记符含义八进制方式 \ a Ctrl-G 铃声\ 0 0 7 \ b Ctrl-H 退格符\ 0 1 0 \f Ctrl-L 走行换页\ 0 1 4 \n Ctrl-J 新行\ 0 1 2 \ r Ctrl-M 回车\ 0 1 5 \t Ctrl-I tab键\ 0 11 \ v Ctrl-X \ 0 3 0 |
代码: |
[sam@chenwy split]$ cat opps.txt And the cowwwwws went homeeeeeeeeeeeee Or did theyyyyyyyyyyyyy |
代码: |
[sam@chenwy split]$ tr -s "[a-z]" < opps.txt And the cows went home Or did they |
代码: |
[sam@chenwy split]$ cat opps.txt | tr -s "[a-z]" And the cows went home Or did they |
代码: |
[sam@chenwy split]$ cat plane.txt plane.txt 9879932 Spitfire 190992 Lancaster 238991 Typhoon |
代码: |
[sam@chenwy split]$ tr -s "[2]" < plane.txt plane.txt 9879932 Spitfire 190992 Lancaster 238991 Typhoon |
代码: |
[sam@chenwy split]$ tr -s "[\n]" < plane.txt plane.txt 9879932 Spitfire 190992 Lancaster 238991 Typhoon |
代码: |
[sam@chenwy split]$ echo "May Day,May Day,Going Down.." | tr "[a-z]" "[A-Z]" MAY DAY,MAY DAY,GOING DOWN.. |
代码: |
[sam@chenwy split]$ echo "May Day,May Day,Going Down.." | tr "[:lower:]" "[:upper:]" MAY DAY,MAY DAY,GOING DOWN.. |
代码: |
[sam@chenwy split]$ cat diary.txt mondy 10:50 Tuesday 15:00 wednesday 15:30 thurday 10:30 Fridya 09:20 |
代码: |
[sam@chenwy split]$ tr -cs "[a-z][A-Z]" "[2*]" Tuesday wednesday thurday Fridya |
代码: |
[sam@chenwy split]$ cat -v stat.tr Boxes paper 12^M Clips metal 50^M Pencils-meduim 10^M ^Z |
代码: |
[sam@chenwy split]$ tr -s "[52]" "\n" [sam@chenwy split]$ cat -v stam.tmp Boxes paper 12 Clips metal 50 Pencils-meduim 10 |
代码: |
[sam@chenwy split]$ tr -s "[5]" "\n" < stat.tr |cat -v Boxes paper 12 Clips metal 50 Pencils-meduim 10 ^Z |
代码: |
[sam@chenwy split]$ tr -s "[5]" "\n" < stat.tr >stat1.tr [sam@chenwy split]$ cat stat1.tr Boxes paper 12 Clips metal 50 Pencils-meduim 10 |
代码: |
[sam@chenwy split]$ tr -s "[\r]" "\n" < stat.tr |
代码: |
[sam@chenwy split]$ tr -s "\r" "\n" < stat.tr |
代码: |
[sam@chenwy split]$ tr -s "[52]" "[2*]" < stat.tr Boxes paper 12 Clips metal 50 Pencils-meduim 10 |
代码: |
[sam@chenwy split]$ tr -s "[1]" "[0*]" < stat.tr >temp.txt [sam@chenwy split]$cat -v temp.txt Boxes paper 12^M Clips metal 50^M Pencils-meduim 10^M ^Z |
代码: |
[sam@chenwy split]$ tr -s "[:]" "[\t]" < passwd root x 0 0 root /root /bin/bash bin x 1 1 bin /bin /sbin/nologin daemon x 2 2 daemon /sbin /sbin/nologin ..................... |
代码: |
[sam@chenwy split]$ tr -s "[:]" "[1]" < passwd |
代码: |
[sam@chenwy split]$ cat hdisk.txt 15566 hdisk3 456554 hdisk2 0000 hdisk1 |
代码: |
[sam@chenwy split]$ tr "[0*4]" "*" < hdisk.txt 15566 hdisk3 456554 hdisk2 **** hdisk1 |
代码: |
[sam@chenwy split]$ tr "[0*4]" "[*]" < hdisk.txt 15566 hdisk3 456554 hdisk2 ]]]] hdisk1 |