【发布时间】:2013-10-25 01:10:34
【问题描述】:
试图回答Using Bash/Perl to modify files based on each file's name 以我不知道如何同时使用find 和sed 的方式结束。
假设有一个特定的文件结构,我们要在其中更改一行,并附加文件名。
如果它是一个普通的for 循环,我们会这样做:
for file in dir/*
do
sed -i "s/text/text plus $file/g" $file
done
但是假设我们想使用find 来更改所有子目录中的文件。在这种情况下,我会使用...
find . -type f -exec sed -i "s/text/text plus {}/g" {} \;
^
it does not like this part
但是sed 中的这些{} 不被接受,我得到了错误
sed: -e expression #1, char 20: `s' 的未知选项
我发现了一些类似的问题 (1),但无法概括到足以让我在这种情况下理解它。
我相信你们会为此提供一个很好的解决方案。谢谢!
【问题讨论】: