标签:使用 oracl 重复 net acl tuesday oracle 分类 转义字符
shell中tr的用法
紫颖 2011-09-27 11:59:43 22794 收藏 3
分类专栏: Linux 知识小结 文章标签: shelloraclelinuxdelete
版权
?tr(translate缩写)主要用于删除文件中的控制字符,或进行字符转换。
语法:tr [–c/d/s/t] [SET1] [SET2]
SET1: 字符集1
SET2:字符集2
-c:complement,用SET2替换SET1中没有包含的字符
-d:delete,删除SET1中所有的字符,不转换
-s: squeeze-repeats,压缩SET1中重复的字符
-t: truncate-set1,将SET1用SET2转换,一般缺省为-t
?
1、去除重复的字符
$ echo aaacccddd | tr -s [a-z]
acd
$ echo aaacccddd | tr -s [abc]
acddd
?
2、删除空白行
$ cat test.txt
I love linux!
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
Hello World!
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
Shell is worthy to been studied
$ cat test.txt | tr -s ["\n"]
I love linux!
Hello World!
Shell is worthy to been studied
$ cat test.txt | tr -s "[\012]"
I love linux!
Hello World!
Shell is worthy to been studied
?
3、大小写相互转换
$ echo "Hello World I Love You" |tr [-t] [a-z][A-Z]
HELLO WORLD I LOVE YOU
$ echo "Hello World I Love You" |tr [A-Z] [a-z]
hello world i love you
$ echo "Hello World I Love You" |tr [:lower:][:upper:]
HELLO WORLD I LOVE YOU
?
4、删除指定的字符
$ cat test.txt
Monday???? 09:00
Tuesday??? 09:10
Wednesday? 10:11
Thursday?? 11:30
Friday???? 08:00
Saturday?? 07:40
Sunday???? 10:00
$ cat test.txt | tr -d "[0-9][: ]"
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
?
5、利用-c进行补集的替换
$ cat test.txt
Monday???? 09:00
Tuesday??? 09:10
Wednesday? 10:11
Thursday?? 11:30
Friday???? 08:00
Saturday?? 07:40
Sunday???? 10:00
cat test.txt|tr -cs? "[a-z][A-Z]" "\n"
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
再来看一个例子:
[oracle@SOR_SYS~]$ echo 172.16.30.141|tr -cd .
...You have new mail in /var/spool/mail/oracle
[oracle@SOR_SYS~]$ echo 172.16.30.141|tr -cd .|wc -c
3
————————————————
版权声明:本文为CSDN博主「紫颖」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhuying_linux/java/article/details/6825568
标签:使用 oracl 重复 net acl tuesday oracle 分类 转义字符
原文地址:https://www.cnblogs.com/syy1757528181/p/13168772.html