使用以下代码,将文件名添加到每行开头并将输出发送到单个文件中。
ls | while read file; do sed -e "s/^/$file/g" $file > out; done
我希望使用find
和exec
或者xargs
命令来执行与sed
相同的替换操作 -
find . -type f -exec sed "s/^/{}/g" {} > out +
然而我遇到了一个错误 -
find: 只支持一个 {} 实例与 -exec ... + 结合使用
输入文件如下 -
fileA.txt
A1
A2
fileB.txt
B1
B2
期望的输出
fileA.txt A1
fileA.txt A2
fileB.txt B1
fileB.txt B2
我知道如何使用 awk 做到这一点,但我想用 sed、find 和 exec 或 xargs 来实现。