replacing word after multiple spaces

后端 未结 6 1893
甜味超标
甜味超标 2021-01-20 08:46

I need to replace a word after multiple spaces :

actually the file contains this string :

local   all             all                                         


        
6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-20 09:17

    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

提交回复
热议问题