如何在 Bash 中复制 VSCode 的'search and replace'代码?



我有一个项目,其中包含一个包含文本hello的文件a.txt,以及一个名为b的文件夹,其中包含文件c.txt,其中还包含文本hello。我想运行一个bash命令,用goodbye替换hello的这两个实例,这与VSCode的搜索和替换功能相同。

我试过sed -i '.bak' 's/hello/goodbye/g' *,但它给我的错误是sed: folder: in-place editing only works for regular files

我应该如何处理?我在用MacOS。

您可以使用find来定位需要编辑的文件,并使用--exec参数来运行sed命令。类似的东西

find . -name '*.txt' -type f -exec sed -i '.bak' 's/hello/goodbye/g' {} ;

最新更新