Print rest of the fields in awk

后端 未结 6 1360
遥遥无期
遥遥无期 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:26

    You can use simple awk like this:

    awk '{$2=""}1' file
    

    However this will have an extra OFS in your output that can be avoided by this awk

    awk '{sub($2 OFS, "")}1' file
    

    OR else by using this tr and cut combo:

    On Linux:

    tr -s ' ' < file | cut -d ' ' -f1,f3-
    

    On OSX:

    tr -s ' ' < file | cut -d ' ' -f1 -f3-
    

提交回复
热议问题