Bash - how to put each line within quotation

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

    I used sed with two expressions to replace start and end of line, since in my particular use case I wanted to place HTML tags around only lines that contained particular words.

    So I searched for the lines containing words contained in the bla variable within the text file inputfile and replaced the beginnign with

    and the end with

    (well actually I did some longer HTML tagging in the real thing, but this will serve fine as example)

    Similar to:

    $ bla=foo
    $ sed -e "/${bla}/s#^#

    #" -e "/${bla}/s#\$#

    #" inputfile

    foo

    bar $

提交回复
热议问题