6

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!

Would you please help me?

Thank you

4

1 回答 1

8

Just use 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
于 2013-03-30T09:36:10.057 回答