1

I have an HTML file in that I have a comment line as:

<!-- tag1 --><!-- tag11 --> 

I need to insert a JQ file element in between them.

I have tried and I was able to insert a small string but my string is large in size. Can anyone suggest me an idea?

i=0
code="(jq -r '.["$i"].code' file.json)"; 
eval v=\$$code; 
sed -i 's/(<!-- tag1 -->)\(<!-- tag11 -->)/\1'$v'\2/' index.html;

It threw me an error as:

sed: -e expression #1, char 47: unterminated `s' command

However:

v="xxxxxxx" 
sed -i 's/(<!-- tag1 -->)\(<!-- tag11 -->)/\1'$v'\2/' index.html;

The string is inserted perfectly can anyone help?

1
  • 1
    Probably $v contains a slash /.
    – PerlDuck
    Sep 19, 2018 at 8:13

1 Answer 1

3

According to ramruma, you could try putting the long string in file and then use file contents insertion, as follows:

sed -i "/teststring/r file1.txt" index.html

From sed manual r flag is used for reading file contents.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .