How to escape a single quote inside awk

前端 未结 5 658
攒了一身酷
攒了一身酷 2020-11-28 20:11

I want do the following

awk \'BEGIN {FS=\" \";} {printf \"\'%s\' \", $1}\'

But escaping single quote this way does not work



        
5条回答
  •  無奈伤痛
    2020-11-28 20:32

    For small scripts an optional way to make it readable is to use a variable like this:

    awk -v fmt="'%s'\n" '{printf fmt, $1}'
    

    I found it conveninet in a case where I had to produce many times the single-quote character in the output and the \047 were making it totally unreadable

提交回复
热议问题