我正在尝试传递一组具有已知字符的文件列表,以供sed查找和替换。
对于包含多个.xml文件的目录:
ls -la
file1.xml
file2.xml
file3.xml
每个都包含一个匹配的字符串:
grep -i foo *
file1.xml <foo/>
file2.xml <foo/>
file3.xml <foo/>
使用for循环将foo替换为bar:
for f in *.xml; do ls | sed -i "s|foo|bar|g" ; done
返回值:
sed: no input files
sed: no input files
sed: no input files
我已经找到了一种可行的替代方法,因此这主要是出于我自己的观点。
find /dir/ -name '*.xml' -exec sed -i "s|foo|bar|g" {} \;
您的for
循环中存在缺陷。删除ls
命令,然后将$f
变量作为参数添加到sed -i
,这将filename.xml
在每个位置进行编辑:
for f in *.xml; do sed -i "s|foo|bar|g" "$f"; done
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句