find -exec 上的多个 sed 操作 [英] Multiple sed operations on find -exec
本文介绍了find -exec 上的多个 sed 操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试对 find -exec 操作执行多个 sed 操作.我的代码如下所示:
I am trying to execute multiple sed operations on the find -exec operation. My code looks like this:
find . -name '*.html.haml' -exec sed -i '' 's/restaurant_id/company_id/g' && sed -i '' 's/restaurants/companies/g' && sed -i '' 's/restaurant/company/g' && sed -i '' 's/Restaurants/Companies/g' && sed -i '' 's/Restaurant/Company/g' "{}" \;
这似乎不起作用.我怎么能这样做?
This seems not to work. How could I do that?
错误:
find: -exec: no terminating ";" or "+"
推荐答案
正如其他人所说,问题在于 &&
被解释为执行 sed 命令 find
命令完成,而不是传递一串要在每个文件上执行的命令.
As others have said, the problem is that the &&
is interpereted to execute the sed command after the find
command is finished, instead of passing one string of commands to be executed on each file.
获得所需结果的最简单方法是将所有这些组合成一个带有分号的 sed
命令.像这样:
The easiest way to achieve your desired result is to combine this all into one sed
command with semicolons. Like so:
$ find . -name '*.html.haml' -exec sed -i 's/restaurant_id/company_id/g;s/restaurants/companies/g;s/restaurant/company/g;s/Restaurants/Companies/g;s/Restaurant/Company/g' "{}" \;
这篇关于find -exec 上的多个 sed 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文