替换多个文件扩展名中的文本

bas*_*eps 0 regex sed

我正在尝试使用sed替换几个文件中的一些文本.

例如:在目录及其子目录中的所有txt和md文件中用Haw替换lion.

到目前为止,我从研究中得到的最佳(非工作)尝试是:

find . -type *.txt | xargs sed -i '' 's/lion/hawk/'
Run Code Online (Sandbox Code Playgroud)

还尝试将md添加到txt正则表达式 - *\.(txt | md)会出错.

在此先感谢您的帮助.

bee*_*jay 6

你要

find . -type f \( -name '*.txt' -o -name '*.md' \) -exec sed -i 's/lion/hawk/g' {} \;
Run Code Online (Sandbox Code Playgroud)

-o是两个-name谓词的逻辑OR .您也可以直接使用-exec而不是管道xargs(两者都工作).

编辑更新的引用和parens.