1

I have values in a file like this ' value-to-remove '(without the ' characters). I want to use sed to run through the file and replace the values including the space before and after. I am running this via a bash script. How can I do this?

The sed command I'm using at the moment replaces the values but leaves behind the two spaces.

sed -i 's/ '$value' / /g' test.conf

In script I have

sed -i -e 's/\s'$DOMAIN'-'$SITE'\s/\s/g' gitosis.conf

echoed as

sed -i -e s/\sffff.com-eeee\s/\s/g test.conf

Not working though.

1
  • btw, you should show your input and the wanted output. Commented Jun 5, 2011 at 16:19

2 Answers 2

2

IMHO your sed does not know '\s', so use [ \t], and use double quotes, otherwise your variables will not expand. e.g.:

sed -i -e "s/[ \t]'$DOMAIN'-'$SITE'[ \t]/ /g" gitosis.conf
Sign up to request clarification or add additional context in comments.

Comments

0

Let me know if this is what you need

echo 'Some values to remove value-to-remove and more' | sed -e 's/\svalue-to-remove\s/CHANGED/g'

output: Some values to removeCHANGEDand more

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.