Monday, February 5, 2018

Sed -i change the text start with space

I met a issue that want use sed to replace a line start with space. and new line also start with space.

Just like new line want keep indentation as before.

replaced="    def"
sed -i "/  abc/c   $replaced" temp.txt

in this case ,   the new line will lost the space ,  no indentation

The way to do it :

replaced="\    def"
sed -i "/  abc/c   $replaced" temp.txt

This will keep space after the replacement.


No comments:

Post a Comment