linux系统中提取具有指定列的行

 

1、创建测试数据

[root@centos7 test2]# cat > a.txt
i
s g
z e q
d k i p
m h y
u t
e
^C
[root@centos7 test2]# ls
a.txt
[root@centos7 test2]# cat a.txt
i
s g
z e q
d k i p
m h y
u t
e

 

2、提取列数为3的行

[root@centos7 test2]# cat a.txt
i
s g
z e q
d k i p
m h y
u t
e
[root@centos7 test2]# awk 'NF == 3' a.txt
z e q
m h y

 

3、删除列数为3的行

[root@centos7 test2]# cat a.txt
i
s g
z e q
d k i p
m h y
u t
e
[root@centos7 test2]# awk 'NF != 3' a.txt
i
s g
d k i p
u t
e

 

posted @ 2021-04-15 09:44  小鲨鱼2018  阅读(869)  评论(0编辑  收藏  举报