How to add single quotes around columns using awk

前端 未结 6 2258
庸人自扰
庸人自扰 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条回答
  •  -上瘾入骨i
    2020-12-18 14:00

    You could try this

    awk -F"," -v quote="'" -v OFS="','" '$1=$1 {print quote $0 quote}' file
    
    1. Replace each separator (, comma) with (',' quote-comma-quote) -> (-F"," -v OFS="','")
    2. Add quotes to the begin and end of line -> (print quote $0 quote)

提交回复
热议问题