linux 中 tr命令的-d、-c选项

 

001、-d表示删除

[root@PC1 test02]# ls
a.txt
[root@PC1 test02]# cat a.txt                 ## 测试数据
a f k jH
f k E 3j
s 8 8 34
a j F ej
[root@PC1 test02]# cat a.txt | tr -d 0-9     ## 删除所有的数字
a f k jH
f k E j
s
a j F ej

 

[root@PC1 test02]# ls
a.txt
[root@PC1 test02]# cat a.txt                    ## 测试数据
a f k jH
f k E 3j
s 8 8 34
a j F ej
[root@PC1 test02]# cat a.txt | tr -d a-z       ## 删除所有的小写字母
   H
  E 3
 8 8 34
  F
[root@PC1 test02]# cat a.txt | tr -d a-zA-Z    ## 删除所有的字3
 8 8 34

 。

 

002、-c选项  :补语(Complement Characters)

[root@PC1 test02]# echo "My ip address is 192.168.1.1" | tr -cd 0-9    ## 删除数字以外的所有字符
19216811[root@PC1 test02]#

 

 

posted @ 2023-07-23 23:13  小鲨鱼2018  阅读(1157)  评论(0编辑  收藏  举报