Printing everything except the first field with awk

前端 未结 16 2642
北恋
北恋 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:56

    Maybe the most concise way:

    $ awk '{$(NF+1)=$1;$1=""}sub(FS,"")' infile
    United Arab Emirates AE
    Antigua & Barbuda AG
    Netherlands Antilles AN
    American Samoa AS
    Bosnia and Herzegovina BA
    Burkina Faso BF
    Brunei Darussalam BN
    

    Explanation:

    $(NF+1)=$1: Generator of a "new" last field.

    $1="": Set the original first field to null

    sub(FS,""): After the first two actions {$(NF+1)=$1;$1=""} get rid of the first field separator by using sub. The final print is implicit.

提交回复
热议问题