Select a particular column using awk or cut or perl Select a particular column using awk or cut or perl unix unix

Select a particular column using awk or cut or perl


If the data is unambiguously tab-separated, then cut will cut on tabs, not spaces:

cut -f7 filename

You can certainly do that with awk, too:

awk -F'\t' '{ print $7 }'


If fields are separated by tabs and your concern is that some fields contain spaces, there is no problem here, just:

cut -f 7

(cut defaults to tab delimited fields.)


Judging by the format of your input file, you can get away with delimiting on - instead of spaces:

awk 'BEGIN{FS="-"} {print $2}' filename
  • FS stands for Field Separator, just think of it as the delimiter for input.
  • Given that we are now delimiting on -, your 7th field before now becomes the 2nd field.
  • Save a cat! Specify input file filename as an argument to awk instead.

Alternatively, if your data fields are separated by tabs, you can do it more explicitly as follows:

awk 'BEGIN{FS="\t"} {print $7}' filename

And this will resolve the issue since Out Global Doc Mark looks to be separated by spaces.