Search code examples
linuxunixawkcutgawk

Print Field 'N' to End of Line


I would like to have help or direction on a problem I have in awk.

I have a tab-delimited file with more than 5 fields. I want to output the fields excluding the first 5 fields.

Could you please tell how to write an awk script to accomplish this task?

Best, jianfeng.mao

Do Note the following kind comment:

There are many fields in my files. Different lines have a different number of fields. The number of fields per line is not standard.


Solution

  • I agree with matchew's suggestion to use cut: it's the right tool for this job. But if this is just going to become a part of a larger awk script, here's how to do it:

    awk -F "\t" '{ for (i=6; i<=NF; ++i) $(i-5) = $i; NF = NF-5; print; }