How to use sed in shell script with value containing line break \n?

37 views Asked by At

In my shell script I have conf=2bi5oIl0hldy/p3fe+KMQTVjUSg89ywhdMCaSOAopEVFM\nKlj4RDJcmNcEa1cgxL3sJNBHrw==\n

And I have a ini file that has parameter looks like this:

^PASS= SNlfkDahPoWNYCY0V+Z77iR8bP5GIpp8FL6GX5fBvGhfnvH\nRbtyBU06EGifzFyBvZgrqFi/Dw==\n

('=' might have space before or after)

I need to replace what comes after ^PASS= with the $conf value including the slashes and backslashes and other characters without cutting the string off.

I have this sed expression :

sed -i "/^[^#]/ s|\(\^PASS *= *\)[^ ]*|\1$conf|g" "file.ini"

As a result, I get in file.ini :

^PASS=2bi5oIl0hldy/p3fe+KMQTVjUSg89ywhdMCaSOAopEVFM

Klj4RDJcmNcEa1cgxL3sJNBHrw==\n

So the conf value is breaking to new line, due to \n after the M.

Not sure what I'm doing wrong.

0

There are 0 answers