How to grep and replace

后端 未结 9 1601
囚心锁ツ
囚心锁ツ 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:20

    This works best for me on OS X:

    grep -r -l 'searchtext' . | sort | uniq | xargs perl -e "s/matchtext/replacetext/" -pi
    

    Source: http://www.praj.com.au/post/23691181208/grep-replace-text-string-in-files

提交回复
热议问题