Use awk to Print from nth element to the End of the Line

If you want to extract from the nth token to the end of the line, following is how you can do that with awk:

Given a source file with the following:

line1 — 01   0011 1
line2 — 01   0011 2
line3 — 01   0011 3
line4 — 01   0011 4
line5 — 01   0011 5
line6 — 01   0011 6
line7 — 01   0011 7
line8 — 01   0011 8
line9 — 01   0011 9
line10 — 01   0011 10

If you want remove the 1st, 2nd, and 3rd items from the list, you can use awk to set those fields to an empty value as follows

awk ‘{$1=$2=$3=””; print $0}’ test.out

Which will result in:

   value1 00 0011 1
   value2 00 0011 2
   value3 00 0011 3
   value4 00 0011 4
   value5 00 0011 5
   value6 00 0011 6
   value7 00 0011 7
   value8 00 0011 8
   value9 00 0011 9
   value10 00 0011 10

Leave a Reply