text: user285: 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.
  
  user298: Your awk command is inside double quotes ("") which means that all of the awk field variables (e.g. $3) are being interpreted by the shell. Since $3 is not set in the shell, your awk is trying to compare an empty string and that's why you get the error:
  awk: cmd. line:1: {if( != chrM &&  != chrUn){print ./index_sort.sh}}
  awk: cmd. line:1:      ^ syntax error
  
  Note how the error message shows if( != chrM and not if($3 != chrM. Since you need to use double quotes here because you need both an outer (for parallel) and an inner (for awk) quote, and single quotes can't be nested, you will have to escape the awk variables:
  ls *.bam | parallel "samtools view -h {} | 
      awk '{if(\$3 != "chrM" && \$3 != "chrUn"){print \$0}}' | samtools view -Shb {.}.bam" 
  
  
original_text: 285: <p>This is the one i used for a single bam file to filter its mitochondrial as well as unassembled read</p>
  <pre><code>samtools view -h SRR2920466.bam | awk '{if(<span class="math-container">$3!= "chrM" &amp;&amp; $</span>3 != &quot;chrUn&quot;){print $0}}' | samtools view -Shb - &gt; this.filter.bam 
  </code></pre>
  <p>Is there any way i can do it on multiple files with parallel as i do to index and sort bam files using samtools .</p>
  <p>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</p>
  <pre><code>ls *.bam | parallel &quot;samtools view -h {} | awk '{if(<span class="math-container">$3 != "chrM" &amp;&amp; $</span>3 != &quot;chrUn&quot;){print $0}}'| samtools view -Shb {.}.bam&quot; 
  </code></pre>
  <p>Any help with my above codes? As i get it there is wrong with my pipe .</p>
  <p>After updating the samtools to version 1.9 i ran the small script</p>
  <p>i get this error</p>
  <pre><code>awk: cmd. line:1: {if( != chrM &amp;&amp;  != chrUn){print ./index_sort.sh}}
  awk: cmd. line:1:      ^ syntax error
  awk: cmd. line:1: {if( != chrM &amp;&amp;  != chrUn){print ./index_sort.sh}}
  awk: cmd. line:1:                                    ^ unterminated regexp
  awk: cmd. line:1: {if( != chrM &amp;&amp;  != chrUn){print ./index_sort.sh}}
  awk: cmd. line:1:                                                   ^ unexpected newline or end of string
  awk: cmd. line:1: {if( != chrM &amp;&amp;  != chrUn){print ./index_sort.sh}}
  awk: cmd. line:1:      ^ syntax error
  awk: cmd. line:1: {if( != chrM &amp;&amp;  != chrUn){print ./index_sort.sh}}
  awk: cmd. line:1:                                    ^ unterminated regexp
  awk: cmd. line:1: {if( != chrM &amp;&amp;  != chrUn){print ./index_sort.sh}}
  awk: cmd. line:1:                                                   ^ unexpected newline or end of string
  awk: cmd. line:1: {if( != chrM &amp;&amp;  != chrUn){print ./index_sort.sh}}
  awk: cmd. line:1:      ^ syntax error
  awk: cmd. line:1: {if( != chrM &amp;&amp;  != chrUn){print ./index_sort.sh}}
  awk: cmd. line:1:                                    ^ unterminated regexp
  awk: cmd. line:1: {if( != chrM &amp;&amp;  != chrUn){print ./index_sort.sh}}
  awk: cmd. line:1:                                                   ^ unexpected newline or end of string
  </code></pre>
  <p>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.</p>
   298: <p>Your awk command is inside double quotes (<code>""</code>) which means that all of the awk field variables (e.g. <code>$3</code>) are being interpreted by the shell. Since <code>$3</code> is not set in the shell, your awk is trying to compare an empty string and that's why you get the error:</p>
  
  <pre><code>awk: cmd. line:1: {if( != chrM &amp;&amp;  != chrUn){print ./index_sort.sh}}
  awk: cmd. line:1:      ^ syntax error
  </code></pre>
  
  <p>Note how the error message shows <code>if( != chrM</code> and not <code>if($3 != chrM</code>. Since you <em>need</em> to use double quotes here because you need both an outer (for <code>parallel</code>) and an inner (for awk) quote, and single quotes can't be nested, you will have to escape the awk variables:</p>
  
  <pre><code>ls *.bam | parallel "samtools view -h {} | 
      awk '{if(\$3 != "chrM" &amp;&amp; \$3 != "chrUn"){print \$0}}' | samtools view -Shb {.}.bam" 
  </code></pre>
  