How to add single quotes around columns using awk

前端 未结 6 2257
庸人自扰
庸人自扰 2020-12-18 13:21

Just wondering how can I add single quotes around fields, so I can import it to mysql without warnings or errors.

I have a csv file with lots of content.

         


        
6条回答
  •  独厮守ぢ
    2020-12-18 13:58

    try this:

    awk '{gsub(/^|$/,"\x027");gsub(/,/,"\x027,\x027")}7' file
    

    example

    kent$  echo "16:47:11,3,r-4-VM,250000000.,0.50822578824,131072,0,0,0,0,0"|awk '{gsub(/^|$/,"\x027");gsub(/,/,"\x027,\x027")}7'
    '16:47:11','3','r-4-VM','250000000.','0.50822578824','131072','0','0','0','0','0'
    

提交回复
热议问题