How to find and replace all occurrences of a string recursively in a directory tree?

前端 未结 8 1582
野性不改
野性不改 2020-12-12 18:01

Using just grep and sed, how do I replace all occurrences of:

a.example.com

with

b.example.com

within a

8条回答
  •  爱一瞬间的悲伤
    2020-12-12 18:44

    For me works the next command:

    find /path/to/dir -name "file.txt" | xargs sed -i 's/string_to_replace/new_string/g'
    

    if string contains slash 'path/to/dir' it can be replace with another character to separate, like '@' instead '/'.

    For example: 's@string/to/replace@new/string@g'

提交回复
热议问题