How to print all the columns after a particular number using awk? How to print all the columns after a particular number using awk? shell shell

How to print all the columns after a particular number using awk?


awk '{ s = ""; for (i = 9; i <= NF; i++) s = s $i " "; print s }'


When you want to do a range of fields, awk doesn't really have a straight forward way to do this. I would recommend cut instead:

cut -d' ' -f 9- ./infile

Edit

Added space field delimiter due to default being a tab. Thanks to Glenn for pointing this out


awk '{print substr($0, index($0,$9))}'

Edit:Note, this doesn't work if any field before the ninth contains the same value as the ninth.