vjain27
vjain27

Reputation: 3674

linux command to concatenate multiple files with content separated by filenames?

I am looking for a command that will concatenate multiple files in a directory tree with sames having a pattern such that the resulting file has contents of all the files separated by the name(path) of each file. I tried using find -exec and sed but couldn't succeed.Please help. More specifically I have a directory containing many sub-directories having file named 'test.FAILED'. I want to concatenate all the test.FAILED files separated by their Paths so that I can have a look at all of them at the same time.

Upvotes: 1

Views: 2188

Answers (2)

Marcus Borkenhagen
Marcus Borkenhagen

Reputation: 6656

Using (gnu) find:

find . -name \*.FAILED -print -exec cat "{}" \;

Upvotes: 2

antlersoft
antlersoft

Reputation: 14786

for i in <pattern>
do
    echo "$i"
    cat "$i"
done > output

Upvotes: 5

Related Questions