Bash - how to put each line within quotation

后端 未结 7 1305
既然无缘
既然无缘 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:48

    I use the following command:

    xargs -I{lin} echo \"{lin}\" < your_filename
    

    The xargs take standard input (redirected from your file) and pass one line a time to {lin} placeholder, and then execute the command at next, in this case a echo with escaped double quotes.

    You can use the -i option of xargs to omit the name of the placeholder, like this:

    xargs -i echo \"{}\" < your_filename
    

    In both cases, your IFS must be at default value or with '\n' at least.

提交回复
热议问题