I’m trying to keep most of my genome stats in bed format. This makes it pretty easy to mix and match analyses. However, one task that seems to come up over and over is how to sort the files when they have a header. So I don’t have to remember it and you don’t have to spend anymore time googling it the easy ‘linux’ way to do this is with the following one-liner:

cat file.wheader.bed \
| { head -n 1; tail -n +2 \
| sort -k1,1 -k2,2g; } \
> file.wheader.sorted.bed

Enjoy.

Share →

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">