Suping Chen's Notes

All about Technical issues

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.


Posted by SC at 11:48 AM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Newer Posts Older Posts Home
Subscribe to: Posts (Atom)

Blog Archive

  • ►  2019 (8)
    • ►  June (2)
    • ►  May (1)
    • ►  April (5)
  • ▼  2018 (6)
    • ►  December (2)
    • ►  November (1)
    • ►  September (1)
    • ►  March (1)
    • ▼  February (1)
      • Sed -i change the text start with space
  • ►  2017 (11)
    • ►  October (1)
    • ►  August (1)
    • ►  July (3)
    • ►  June (2)
    • ►  February (3)
    • ►  January (1)
  • ►  2016 (9)
    • ►  October (4)
    • ►  August (1)
    • ►  April (1)
    • ►  March (1)
    • ►  January (2)
  • ►  2015 (12)
    • ►  November (1)
    • ►  September (1)
    • ►  June (2)
    • ►  May (2)
    • ►  March (2)
    • ►  February (1)
    • ►  January (3)
  • ►  2014 (8)
    • ►  December (2)
    • ►  June (2)
    • ►  February (3)
    • ►  January (1)
  • ►  2013 (26)
    • ►  November (1)
    • ►  October (2)
    • ►  September (2)
    • ►  August (1)
    • ►  July (5)
    • ►  June (6)
    • ►  May (8)
    • ►  April (1)
Simple theme. Theme images by gaffera. Powered by Blogger.