linux sort Multi field sort instance resolution
- 2020-06-23 02:39:48
- OfStack
This paper focuses on linux sort multi-field sorting, which is described as follows.
The sort program, which comes with most Linux distributions, is very powerful, except for multi-field sorting
sort has a parameter -ES11en, which specifies fields, has a more complex syntax, and is outside the text range.
Below 1 is 1 section of data (obtained from the gene, only as demo), and the file name is data
[
chr13 3008566 3008677
chr9 3024384 3024515
chr19 3157071 3157172
chr5 3236386 3236476
chr13 3041044 3041191
chr12 3045343 3045532
chr6 3087308 3087625
chr5 3109870 3110091
chr9 3115454 3115531
Fields are separated by Spaces
Now you want to first sequence the genes by chromosome, then the genes on the same chromosome by their starting sites, so this is a multi-field sequence, and the second field is a number, using the sort command as follows
sort -t ' ' -k1,1 -k2n,2 data
Where -t "specifies a column delimited with a space
You can also use
sort +0 -1 +1n -2
The effect is one.
Sorting result
[
chr12 3045343 3045532
chr13 3008566 3008677
chr13 3041044 3041191
chr19 3157071 3157172
chr5 3109870 3110091
chr5 3236386 3236476
chr6 3087308 3087625
chr9 3024384 3024515
chr9 3115454 3115531
conclusion
That is the end of this article on linux sort multi-field sort instance parsing, I hope to help you. Interested friends can continue to refer to other related topics in this site, if there is any deficiency, welcome to comment out. Thank you for your support!