Recursive search and replace in text files on Mac and Linux

后端 未结 14 755
不思量自难忘°
不思量自难忘° 2020-12-02 04:18

In the linux shell, the following command will recursively search and replace all instances of \'this\' with \'that\' (I don\'t have a Linux shell in front of me, but it sho

14条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 04:47

    I used this format - but...I found I had to run it three or more times to get it to actually change every instance which I found extremely strange. Running it once would change some in each file but not all. Running exactly the same string two-four times would catch all instances.

    find . -type f -name '*.txt' -exec sed -i '' s/thistext/newtext/ {} +
    

提交回复
热议问题