I have the following line of code:

sed -i "/MatchText/ s/${tgrepLine}/${tNewLine}/" filename.output

filename.output contains this:

blablabla
PATH=".:/home/root/bin/:/usr/local/bin/"
blablabla

Variable ${tgrepLine} contains:
PATH=".:/home/root/bin/:/usr/local/bin/"
Variable ${tNewLine} contains:
PATH="/home/user/bin/:.:/home/root/bin/:/usr/local/bin/"

As you can see, both variables contains " (double quotes)
If I run the 'sed -i' command, I get an error.
I cant use double quotes within the double quotes of the 'sed' command...

The sed command would look like this:

sed -i "/MatchText/ s/PATH=".:/home/root/bin/:/usr/local/bin/"/PATH="/home/user/bin/:.:/home/root/bin/:/usr/local/bin/"/" filename.output

I must find a solution to this problem. Do I need to use the double quotes in both commands??

Thanks in advance!

Use a different delimiter:

sed -i "/MatchText/ s|${tgrepLine}|${tNewLine}|"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.