Bash - how to put each line within quotation

后端 未结 7 1286
既然无缘
既然无缘 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条回答
  • 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
    
    0 讨论(0)
提交回复
热议问题