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
The `awk` command is one of many commands that can be used to print a range of columns from tabular data in Linux. The `awk` command is can be used directly from the terminal by executing the `awk` script file.
awk '{print $1}' information. txt prints the first column.
If you notice awk 'print $1' prints first word of each line. If you use $3, it will print 3rd word of each line.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With