I have many files of the same name distributed in many sub-directories with different names (though all at the same level). I'd like to concatenate all the files of the same into a new file with that name. I'd like this new file to be in the parent directory.
I've already tried a few answers posted here on SE: How to move files with same name and concatenate
Here's what I've tried and the issues:
find */*/*/seq/in/ -type f -name '*.fasta' -exec bash -c 'cat "{}" >> new_file' \;
This concatenated all files with suffix .fasta, into one file call new_file, not just those with matching names.
for file in */*/*/seq/in/*.fasta;
do
cat "$file" >> "$file.cat" done
This just made a copy of each file in the same original sub-directory and appended it with .cat
What am I doing wrong? Thank you so much!
new file
in the same directory and appends the data into it. The second creates a file in the same directory with the suffix of.cat
and appends the data into it. If by parent directory, you mean the top level directory then you need to prepend that to the path of the file. You can set the file to be /top/pathto/directory/newfile in your script. – Nasir Riley Apr 5 '18 at 16:31