comma separated values to single inverted quote and comma separated values

前端 未结 4 429
自闭症患者
自闭症患者 2021-01-07 13:49

I have data as

    abc,defg,hijklm,op,qrs,tuv

I want this data to be converted to

    \'abc\',\'defg\',\'hijklm\',\'op\',         


        
4条回答
  •  星月不相逢
    2021-01-07 13:53

    Using awk gsub function. Here all the "," are replaced by ',' and start and the end of the line is replaced by "'".

    echo $x |awk -v q="'" '{gsub(/,/, q "&" q);gsub(/^|$/,q)}1'
    'abc','defg','hijklm','op','qrs','tuv'
    

提交回复
热议问题