linux 中如何提取一列中纯数字或者纯字母的行

 

001、纯数字

[root@PC1 test1]# ls
a.txt
[root@PC1 test1]# cat a.txt                     ## 测试文本
sdf324
7fy323td34
342
fff
435
tih
6334
s234dfg65
[root@PC1 test1]# grep "^[0-9]\+$" a.txt       ## 提取纯数字的行
342
435
6334

 

002、纯字母

[root@PC1 test1]# ls
a.txt
[root@PC1 test1]# cat a.txt                          ## 测试文本
sdf324
7fy323td34
342
fff
435
tih
6334
s234dfg65
[root@PC1 test1]# grep "^[a-zA-Z]\+$" a.txt         ## 提取纯字母的行
fff
tih

 

003、提取即包含数字同时又包含字母的行

[root@PC1 test1]# ls
a.txt
[root@PC1 test1]# cat a.txt                                              ## 测试文本
sdf324
7fy323td34
342
fff
435
tih
6334
s234dfg65
[root@PC1 test1]# grep -E "[a-zA-Z][0-9]|[0-9][a-zA-Z]" a.txt           ## 提取即包含数字又包含字母的行
sdf324
7fy323td34
s234dfg65

 。

 

posted @ 2024-02-09 12:24  小鲨鱼2018  阅读(54)  评论(0编辑  收藏  举报