Reputation: 6106
If I want to print, say, the fourth column till the tenth column, I can use:
awk '{for( i=4; i<=10; i++ ){printf( "%s ", $i )}; printf( "\n"); }
But what if I want to print columns 1, 3, and then 4-10, and then 12?
Upvotes: 0
Views: 38
Reputation: 92854
awk solution:
awk '{ for(i=1;i<=12;i++) if(i!~/^(2|11)$/) printf "%s ",$i; print "" }' file
if(i!~/^(2|11)$/)
- ensures that it's not the 2nd or the 11th field. You can extend the alternation group (2|11|...)
to multiple field numbers that should be skippedUpvotes: 2
Reputation: 133518
Try following and let me know if this helps.
awk '{printf("%s %s",$1,$3);for( i=4; i<=10; i++ ){printf( "%s ", $i )}; printf(" %s\n",$12);}' Input_file
Upvotes: 1