setting the output field separator in awk

后端 未结 2 861
面向向阳花
面向向阳花 2020-12-09 09:32

I\'n trying this statement in my awk script (in a file containing separate code, so not inline), script name: print-table.awk

BEGIN {FS = \"\\t\";OFS = \",\"         


        
相关标签:
2条回答
  • 2020-12-09 09:58

    You need to alter one of the field in awk:

    awk 'BEGIN {FS="\t";OFS=","; print "about to open the file"} {$1=$1}1' file
    
    0 讨论(0)
  • 2020-12-09 10:03

    You need to convince awk that something has changed to get it to reformat $0 using your OFS. The following works though there may be a more idiomatic way to do it.

    BEGIN {FS = "\t";OFS = "," ; print "about to open the file"}
    {$1=$1}1
    END {print "about to close stream" }
    
    0 讨论(0)
提交回复
热议问题