Matching strings even if they start with white spaces in SED -
I'm having trouble matching strings even if they start with any number of white spaces in regular expression It has been a very short time since starting to use, so I need some help
Here is an example. I have a file (file.txt) which has two rows
  # string1 = 'test one' string1 = 'test two'   I am trying to change the value of the second line without affecting row 1, so I used it
  sed -i "s | string1 =. * $ | String 1 = ' Test three '| g "  It changes the values of both lines, how can I change only the value of the second string?
thanks
 With gnu sed, you can  \ s , while other SAL implementations usually work with the  [[: space:]]  character group. Therefore, choose one of these: 
  sed 's / ^ \ s * AWord / AnotherWord /' sed 's / ^ [[space:]] * AWord / AnotherWord /'    Since you are using  -i , I agree to GNU sed in any way, you probably should not re-type your word, because it is a Introducing the possibility of typos I had to go with it: 
  sed -i "s / ^ \ (\ s * string1 = \). * / \ 1 'new value' / "File    if you do not preserve leading whitespace You want to move out of the legs  \ s * . 
Comments
Post a Comment