Print rest of the fields in awk

后端 未结 6 1373
遥遥无期
遥遥无期 2021-02-02 06:46

Suppose we have this data file.

john 32 maketing executive
jack 41 chief technical officer
jim  27 developer
dela 33 assistant risk management officer

6条回答
  •  悲哀的现实
    2021-02-02 07:13

    Approach using awk that would not require gawk or any state mutations:

    awk '{print $1 " " substr($0, index($0, $3));}' datafile
    

    UPD

    solution that is a bit longer, but will stand up the case when $1 or $2 contains $3:

    awk '{print $1 " " substr($0, length($1 $2) + 1);}' data
    

    Or even more robust if you have custom field separator:

    awk '{print $1 " " substr($0, length($1 FS $2 FS) + 1);}' data
    

提交回复
热议问题