Per*_*o69 5 bash recursion cat
我想将多个同名的文件递归地定位到另一个文件。有一个较早的问题“ Recursive cat all the files into single file ”帮助我开始。不过我想实现相同的目标,以便每个文件前面都有文件名和路径,不同的文件最好用空行或 ----- 或类似的东西分隔。所以生成的文件将如下所示:
files/pipo1/foo.txt
flim
flam
floo
files/pipo2/foo.txt
plim
plam
ploo
Run Code Online (Sandbox Code Playgroud)
有什么办法可以在 bash 中实现这一点吗?
当然!您不只是cating 文件,只需链接操作来打印文件名、cat 文件,然后添加换行符:
find . -name 'foo.txt' \
-print \
-exec cat {} \; \
-printf "\n"
Run Code Online (Sandbox Code Playgroud)