I need to run a java program that merge multiple files with a *bam
extension. the structure of the program is:
java -jar mergefiles.jar \
I=file1.bam \
I=file2.bam \
I=file3.bam \
O=output.bam
So, I am trying the run this program for all *bam files in a directory. Initially, I try to create a list with the names of the *bam files (filenames.txt)
file1.bam
file2.bam
file3.bam
and using the 'while' command, like:
while read -r line; do
java -jar MergeFiles.jar \
I=$line \
O=output.bam
done < filenames.txt
However, the program executed for each *bam
file in the text file but not all together (merge only one file per time, and overwrite the output). So, how I can run the program to merge all *bam
files recursively?
Also, there are other option in the bash (e.g. using a loop for) to solve this issue?
Thanks in advance.