Using grep and sed to find and replace a string

后端 未结 8 1786
耶瑟儿~
耶瑟儿~ 2020-11-30 18:41

I am using the following to search a directory recursively for specific string and replace it with another:

grep -rl oldstr path | xargs sed -i \'s/oldstr/ne         


        
8条回答
  •  时光取名叫无心
    2020-11-30 19:34

    I think that without using -exec you can simply provide /dev/null as at least one argument in case nothing is found:

    grep -rl oldstr path | xargs sed -i 's/oldstr/newstr/g' /dev/null
    

提交回复
热议问题