Created
August 25, 2015 20:26
-
-
Save crazyhottommy/85de6ed22efa541ada17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## imagine we have a file with one line header, and we want to keep the header after sorting | |
## use subshells http://bash.cyberciti.biz/guide/What_is_a_Subshell%3F | |
(sed -n '1p' your_file; cat your_file | sed '1d' | sort) > sort_header.txt | |
## if you have two header lines and want to keep both of them: | |
(sed -n '1,2p' your_file; cat your_file | sed '1,2d' | sort) > sort_header.txt | |
## if you have many lines starting with "#" as header, like vcf files | |
(grep "^#" my_vcf; grep -v "^#" my_vcf | sort -k1,1V -k2,2n) > sorted.vcf | |
## one can also use awk | |
cat my_vcf | awk '$0~"^#" { print $0; next } { print $0 | "LC_ALL=C sort -k1,1V -k2,2n" }' | |
## I am a useless cat user :) http://stackoverflow.com/questions/11710552/useless-use-of-cat | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment