Select a particular column using awk or cut or perl

后端 未结 4 1210
天涯浪人
天涯浪人 2021-02-04 03:20

I have a requirement to select the 7th column from a tab delimited file. eg:

cat filename | awk \'{print $7}\'

The issue is that the data in th

4条回答
  •  半阙折子戏
    2021-02-04 03:45

    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.

提交回复
热议问题