Hi!
I'm in trouble, I would like to use the find
command with multiple -exec
flag and print the result in a file. So far, I could do the following, which works perfectly, however I would like to add another -exec
command:
find ./ref_mapped/ -name '*.sam' -exec ./samtools-1.10/samtools flagstat {} \; > bwa_ell
Here, I run samtools flagstat on all file with a .sam extension and print the result in a file called bwa_ell. However, I would like to include the names of the file, so I will be able to tell which result is for which file.
I would like to implement this somehow: -exec grep -l
or something similar to include file names along with the results..Unfortunately, I could not succeed so far. :(
May I kindly ask is it possible at all?
I spent a half day on this...I think I have a solution...
it seems working but not sure if it is correct...please someone confirm!
I have not used
-exec
with find. But a similar approach other than gnu parallel is to usexargs
. It is a command I often find handy and it executes a give command taking arguments from stdin. An example would be.find -type f -name '*.bam' |xargs -i{} sh -c "echo {} && samtools flagstat {}" > bwa_ell