This is a test version of Biostars. For the public version, visit https://www.biostars.org.
sam header is not recognized by awk?

Why doesn't awk recognize the sam header? I match on ^@ and it will print to stdout but not to a file. It prints to stdout but never finishes.

awk '/^@/ {print}' filename

I can't make any sense of this.

Thanks!

sequencing samtools next-gen awk
awk '/^@/{print}!/^@/{exit}'

2 answers

It prints to stdout but never finishes.

It's got perhaps several dozen headers to read through and print out, followed by perhaps several hundred million alignment records to read though. I'm sure it will finish if you wait long enough!

Perhaps you should consider samtools view -H or similar.

For file 1.t:

@HD VN:1.5 SO:coordinate
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *

awk '/^@/ {print}' 1.t > 2.t

And 2.t will get the output. It works in mawk and gawk.

Log in to answer this question.