Remove first columns then leave remaining line untouched in awk

first as ED commented, you have to use FS as field separator in awk. tab becomes space in your output, because you didn't define OFS.

awk 'BEGIN{FS=OFS="\t"}{$1=$2=$3="";print}' file

this will remove the first 3 fields, and leave rest text "untouched"( you will see the leading 3 tabs). also in output the <tab> would be kept.

awk 'BEGIN{FS=OFS="\t"}{print $4,$5,$6}' file

will output without leading spaces/tabs. but If you have 500 columns you have to do it in a loop, or use sub function or consider other tools, cut, for example.


Actually this can be done in a very simple cut command like this:

cut -f4- inFile

If you don't want the field separation altered then use sed to remove the first 3 columns instead:

sed -r 's/(\S+\s+){3}//' file

To store the changes back to the file you can use the -i option:

sed -ri 's/(\S+\s+){3}//' file

Tags:

Unix

Shell

Awk