In the directory I am working on I have two files with the extension .sam
:
PD180425_aligned_minimap.sam
PD180793_aligned_minimap.sam
For each of these two files, I need to apply a command that looks like the following:
samtools view -Sb pattern.sam > pattern.bam
I am trying to use xargs
for that. What I am trying to do is to capture the prefix before _aligned_minimap
and use that to save to my output. What I tried is the following:
ls *.sam | cut -d "_" -f 1 | xargs -i samtools view -Sb {}_aligned_minimap.sam > {}_aligned_minimap.bam
I would be expecting to have to files generated i.e. PD180425_aligned_minimap.bam
and PD180793_aligned_minimap.bam
. Although my command is running, I see on the directory I am working on that the file {}_aligned_minimap.bam
was generated, which indicates that the input I am trying to capture with xargs (PD180425
and PD180793
) is not working.
How can I go about doing this?