This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Ignore SAM header section using awk

Hi all,

I'm using awk to filter my sam file (aligned_reads.sam) using a text file (values.txt). I need to tell it to ignore the first few lines (header section) of the sam file. Any ideas how I can specify that within this code?

awk 'FNR==NR { a[$1]; next } !($3 in a)' values.txt aligned_reads.sam > filtered_aligned_reads.sam

Thx

sam sequencing bam

1 answer

Use process substitution instead of supplying the SAM file directly.

awk 'do_awk_stuff' values.txt <(samtools view aligned_reads.sam) >filtered_aligned_reads.sam

In fact, see if samtools can directly filter your sam instead of having awk do it.

That fixed it! thanks very much!

Log in to answer this question.