Print a comma except on the last line in Awk

前端 未结 6 1860
余生分开走
余生分开走 2021-01-02 00:30

I have the following script

awk \'{printf \"%s\", $1\"-\"$2\", \"}\' $a >> positions;

where $a stores the name of the fi

6条回答
  •  时光取名叫无心
    2021-01-02 01:08

    Here's a better way, without resorting to coreutils:

    awk 'FNR==NR { c++; next } { ORS = (FNR==c ? "\n" : ", "); print $1, $2 }' OFS="-" file file
    

提交回复
热议问题