How to grep and replace

后端 未结 9 1595
囚心锁ツ
囚心锁ツ 2020-11-27 08:47

I need to recursively search for a specified string within all files and subdirectories within a directory and replace this string with another string.

I know that t

9条回答
  •  佛祖请我去吃肉
    2020-11-27 09:44

    You could even do it like this:

    Example

    grep -rl 'windows' ./ | xargs sed -i 's/windows/linux/g'
    

    This will search for the string 'windows' in all files relative to the current directory and replace 'windows' with 'linux' for each occurrence of the string in each file.

提交回复
热议问题