Printing everything except the first field with awk

前端 未结 16 2648
北恋
北恋 2020-12-04 07:04

I have a file that looks like this:

AE  United Arab Emirates
AG  Antigua & Barbuda
AN  Netherlands Antilles
AS  American Samoa
BA  Bosnia and Herzegovina         


        
16条回答
  •  爱一瞬间的悲伤
    2020-12-04 07:43

    Yet another way...

    ...this rejoins the fields 2 thru NF with the FS and outputs one line per line of input

    awk '{for (i=2;i<=NF;i++){printf $i; if (i < NF) {printf FS};}printf RS}'
    

    I use this with git to see what files have been modified in my working dir:

    git diff| \
        grep '\-\-git'| \
        awk '{print$NF}'| \
        awk -F"/" '{for (i=2;i<=NF;i++){printf $i; if (i < NF) {printf FS};}printf RS}'
    

提交回复
热议问题