与AWK打印列 [英] print columns with AWK
本文介绍了与AWK打印列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试着只打印奇数列,但我做不到!
I tried to print only odd columns but I could not!
awk '{for (i=1; i<=NF; i++) print $2*i-1}' file > test
但它在一列打印的一切!
but it prints everything in one column!
你能帮我吗?
感谢您
推荐答案
只需使用 I + = 2
:
awk '{ for (i=1;i<=NF;i+=2) print $i }' file > test
有关的新要求,才使空的偶数列:
For the new requirements, just make null the 'even' columns:
awk '{ for (i=2;i<=NF;i+=2) $i="" }1' file > test
这篇关于与AWK打印列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文