我正在尝试使用它列出带有自定义文本的文件名称(我的另一个命令)。我使用以下命令:
grep -rl --include=*.php --include=*.html --include=*.js 'ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js' httpdocs/test/ |
xargs echo "sed -i 's~ajax.googleapis.com\/ajax\/libs\/jquery\/3.6.0\/jquery.min.js~example.com\/js\/included\/jquery3_6.min.js~g';" {} \; >> list_js_sed.txt
上述命令执行正常,没有任何错误,并创建一个包含以下文本的文件“list_js_sed.txt”:
sed -i 's~ajax.googleapis.com\/ajax\/libs\/jquery\/3.6.0\/jquery.min.js~example.com\/js\/included\/jquery3_6.min.js~g'; {} ; httpdocs/test/ssi/ss/test1.html httpdocs/test/ssi/test2.html httpdocs/test/test_ss.php
但我希望结果是这样的:
sed -i 's~ajax.googleapis.com\/ajax\/libs\/jquery\/3.6.0\/jquery.min.js~example.com\/js\/included\/jquery3_6.min.js~g' httpdocs/test/ssi/ss/test1.html;
sed -i 's~ajax.googleapis.com\/ajax\/libs\/jquery\/3.6.0\/jquery.min.js~example.com\/js\/included\/jquery3_6.min.js~g' httpdocs/test/ssi/test2.html;
sed -i 's~ajax.googleapis.com\/ajax\/libs\/jquery\/3.6.0\/jquery.min.js~example.com\/js\/included\/jquery3_6.min.js~g' httpdocs/test/test_ss.php;
请帮我修复这个问题。
答案1
\;
不需要xargs
...由于未设置占位{}
符,因此未按预期使用,而是用作文字字符串...因此您可以使用:
grep -rl --include=*.php --include=*.html --include=*.js 'ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js' httpdocs/test/ | xargs -I {} echo "sed -i 's~ajax.googleapis.com\/ajax\/libs\/jquery\/3.6.0\/jquery.min.js~example.com\/js\/included\/jquery3_6.min.js~g' {};" >> list_js_sed.txt
附注:有两件事(不重要但值得一提):