我有一个项目,其中包含一个包含文本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' {} ;