5

I'd like to cat recursively several files with same name to another file. There's an earlier question "Recursive cat all the files into single file" which helped me to get started. However I'd like to achieve the same so that each file is preceded by the filename and path, different files preferably separated with a blank line or ----- or something like that. So the resulting file would read:

files/pipo1/foo.txt
flim 
flam 
floo

files/pipo2/foo.txt
plim
plam
ploo

Any way to achieve this in bash?

Community
  • 1
  • 1
Peregrino69
  • 255
  • 2
  • 11

1 Answers1

5

Of course! Instead of just cating the file, you just chain actions to print the filename, cat the file, then add a line feed:

find . -name 'foo.txt' \
  -print \
  -exec cat {} \; \
  -printf "\n"
that other guy
  • 116,971
  • 11
  • 170
  • 194