Bash - how to put each line within quotation

后端 未结 7 1289
既然无缘
既然无缘 2020-12-30 21:14

I want to put each line within quotation marks, such as:

abcdefg
hijklmn
opqrst

convert to:

\"abcdefg\"
\"hijklmn\"
\"opqrs         


        
7条回答
  •  -上瘾入骨i
    2020-12-30 21:57

    paste -d\" /dev/null your-file /dev/null
    

    (not the nicest looking, but probably the fastest)

    Now, if the input may contain quotes, you may need to escape them with backslashes (and then escape backslashes as well) like:

    sed 's/["\]/\\&/g; s/.*/"&"/' your-file
    

提交回复
热议问题