Add double quotes around fields in AWK script output?

前端 未结 6 1415
臣服心动
臣服心动 2021-02-04 01:33

I have written an awk script that converts a distributor flatfile into a CSV importable into Magento. This file is semi-colon delimited.

It is not putting quotes around

6条回答
  •  攒了一身酷
    2021-02-04 02:06

    In my opinion, we could use printf (formated output) and double quote is obtain with \" into format string.

    e.g.

    gawk 'BEGIN{print "WKT,punto";}{printf "\"LINESTRING Z (%f %f 0,%f %f 0)\",\"%d"\n",$3,$2,$4,$5,$1}' Frecce_geoloc_12-24.txt

    output:

                      $3         $2           $4         $5            $1
    

    "LINESTRING Z (-72.319686 -50.609328 0,-50.609309 -72.319499 0)","6582"

    "LINESTRING Z (-72.319245 -50.609215 0,-50.609195 -72.319052 0)","6583"

    "LINESTRING Z (-72.318799 -50.609101 0,-50.609081 -72.318607 0)","6584"

    "LINESTRING Z (-72.318366 -50.608990 0,-50.608969 -72.318169 0)","6585"

提交回复
热议问题