linux 中 tr -dc 命令

发布时间 2023-10-01 23:23:19作者: 小鲨鱼2018

 

001、tr -dc string: 表示删除字符以外(补集complement)的所有字符

[root@pc1 test]# ls
a.txt
[root@pc1 test]# cat a.txt                            ## 测试文本
01 02 abd ef
03jkk. 04, f
05 f 06
[root@pc1 test]# cat a.txt | tr -dc [:digit:]        ## 表示删除数字补集以外的所有字符
010203040506[root@pc1 test]#

 

002、

[root@pc1 test]# ls
a.txt
[root@pc1 test]# cat a.txt                       ## 测试文本
01 02 abd ef
03jkk. 04, f
05 f 06
[root@pc1 test]# cat a.txt | tr -dc [:alpha:]     ## 表示删除字母以外的所有内容
abdefjkkff[root@pc1 test]#

 

003、

[root@pc1 test]# ls
a.txt
[root@pc1 test]# cat a.txt
01 02 abd ef
03jkk. 04, f
05 f 06
[root@pc1 test]# cat a.txt | tr -dc [:alpha:]\|"\n"     ## 删除除字母和换行符以外的所有内容
abdef
jkkf
f
[root@pc1 test]# cat a.txt | tr -dc [:alpha:]\|"\n"\|" "   ## 删除字母、换行符和空格以为的所有内容
  abd ef
jkk  f
 f

 。