Linux 中 awk命令提取偶数列数据

 

001、

[root@localhost test]# ls
a.txt
[root@localhost test]# cat a.txt           ## 测试数据
01      02      03      04      05
07      08      09      10      11
13      14      15      16      17
19      20      21      22      23
25      26      27      28      29
[root@localhost test]# awk '{for(i = 2; i <=NF; i += 2) {printf "%s%s", $i, (i == NF || i == NF - 1 ? ORS:OFS)}}' a.txt    ## i == NF适用与总列数偶数列的数据; i== NF - 1适用于总列数是奇数列
02 04
08 10
14 16
20 22
26 28

image

。 

 

posted @ 2025-10-03 23:49  小鲨鱼2018  阅读(6)  评论(0)    收藏  举报