This is the one i used for a single bam file to filter its mitochondrial as well as unassembled read
samtools view -h SRR2920466.bam | awk '{if($3!= "chrM" && $3 != "chrUn"){print $0}}' | samtools view -Shb - > this.filter.bam
Is there any way i can do it on multiple files with parallel as i do to index and sort bam files using samtools .
So i tried this ,which is of course not working as its not able to pipe properly because it shows me error regarding additional fonts
ls *.bam | parallel "samtools view -h {} | awk '{if($3 != "chrM" && $3 != "chrUn"){print $0}}'| samtools view -Shb {.}.bam"
Any help with my above codes? As i get it there is wrong with my pipe .
After updating the samtools to version 1.9 i ran the small script
i get this error
awk: cmd. line:1: {if( != chrM && != chrUn){print ./index_sort.sh}}
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: {if( != chrM && != chrUn){print ./index_sort.sh}}
awk: cmd. line:1: ^ unterminated regexp
awk: cmd. line:1: {if( != chrM && != chrUn){print ./index_sort.sh}}
awk: cmd. line:1: ^ unexpected newline or end of string
awk: cmd. line:1: {if( != chrM && != chrUn){print ./index_sort.sh}}
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: {if( != chrM && != chrUn){print ./index_sort.sh}}
awk: cmd. line:1: ^ unterminated regexp
awk: cmd. line:1: {if( != chrM && != chrUn){print ./index_sort.sh}}
awk: cmd. line:1: ^ unexpected newline or end of string
awk: cmd. line:1: {if( != chrM && != chrUn){print ./index_sort.sh}}
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: {if( != chrM && != chrUn){print ./index_sort.sh}}
awk: cmd. line:1: ^ unterminated regexp
awk: cmd. line:1: {if( != chrM && != chrUn){print ./index_sort.sh}}
awk: cmd. line:1: ^ unexpected newline or end of string
I have 30 bam files i tried with 2 to see if its working or not , after the suggestion of @WouterDeCoster i tried the above one after updating samtools . the basic samtool with egrep works but for multiple file i couldn;t do it.