I need to replace a word after multiple spaces :
actually the file contains this string :
local all all
Try this one:
sed -i.bak -e "s/\(all[ ]\+\)peer/\1md5/g" file
You need to escape ()+
characters.
Space could be like: [ ]
with \+
you say that it should be more than 0. Replace it with *
if in some cases you do not have a space between "all" and "peer"
In the replace part you should use \1
- back-reference to the first found part: all
, and only peer
will be replaced with md5