我试图只打印奇数列,但我不能!
awk '{for (i=1; i<=NF; i++) print $2*i-1}' file > test
Run Code Online (Sandbox Code Playgroud)
但它在一列中打印所有内容!
你能帮帮我吗?
谢谢
只需使用i+=2:
awk '{ for (i=1;i<=NF;i+=2) print $i }' file > test
Run Code Online (Sandbox Code Playgroud)
对于新要求,只需将'even'列设为null:
awk '{ for (i=2;i<=NF;i+=2) $i="" }1' file > test
Run Code Online (Sandbox Code Playgroud)