Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change a file's content using sed with multiple quotes and spaces in it?

So I’m working on a Ubuntu Docker image and have to replace a settng in a file using sed.

I’d like to change #$nrconf{restart} = 'i' into $nrconf{restart} = 'a'

The way I understand it is that I have to escape ', $, {, }. I then tried it using this sed command (tried with and without escaping #)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sed -i 's/#\$nrconf\{restart\}[[:space:]]=[[:space:]]\'i\'/\$nrconf\{restart\}[[:space:]]=[[:space:]]\'a\'/g' /etc/needrestart/needrestart.conf

But when I test the command it expects an input and when I run the command in a Docker image I get this error Syntax error: Unterminated quoted string

What am I missing? I think escaping the quotes is correct, I don’t get it

>Solution :

Using sed

$ sed -E "s/^#($nrconf[^']*')[^']*/\1a/" input_file
$nrconf{restart} = 'a'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading