I want to select some columns in a file and run some command on it. so my script is this
awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$19}' test.txt > outpot.txt
but this print it to another file and I tried to do this
awk '{print $1,$2,$3,$4,$5,$6,$7,$9,$10,$11,$12,$13,$14,$15,$16}' test.txt | next commands
(This commands works fine! I did a mistake and I don't know how to remove this question)
is it possible to make this command shorter like instead of writing all columns just write $1-7 && $9-15 && $19
(but this is not really important I just wondered if it's possible). The main thing is to be able to choose that columns
Updated based on glennjackman's suggestion:
awk '{for (i=1;i<=NF;i++) if ((1<=i && i<=7) || (9<=i && i<=15) || i==19) printf("%s ", $i); print ""}' file
To answer one part of your question, in awk script you can do:
{
for (i=1; i<=7; i++)
print $i;
for (i=9; i<=15; i++)
print $i;
print $19;
}
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