开发者

how to find replace value with whitespace using sed in a bash script

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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜