I have a directory called /home/foobar/ which contain numerous text files in numerous sub directories. I need to generate a file which has the merged content of all the files inside this directory structure.
The order in which the files are merged does not matter. I can copy all the files to one directory first and merge then, but in that case the solution must take into account that the files do not have unique names.
32 Answers
It's a simple task for find and cat:
find <path_to_files> -type f -print0 | xargs -0 -I {} cat {} >> mergedThe content of all files in <path_to_files> and in all sub-folders will be added to merged. Therefore remove merged for each new run of the command.
This should work (replacing path/to/dir with the path to the base directory):
for i in $(find /path/to/dir -type "f" ); do cat "$i">>OUTPUT.txt;done 5