Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to sort the input file according the 6th column, which is the score.

Input File:

Sc2/80  20 . A T 86 Pass N=2 F=5;U=4
Sc2/80  20 . A C 80 Pass N=2 F=5;U=4
Sc2/60  55 . G T 90 Pass N=2 F=5;U=4
Sc2/60  55 . G C 99 Pass N=2 F=5;U=4
Sc2/20  39 . C T 97 Pass N=2 F=5;U=4
Sc2/20  39 . C A 99 Pass N=2 F=5;U=4

Expected Output:

Sc2/20 39 . C T 97 Pass N=2 F=5;U=4
Sc2/20 39 . C A 99 Pass N=2 F=5;U=4
Sc2/60 55 . G T 90 Pass N=2 F=5;U=4
Sc2/60 55 . G C 99 Pass N=2 F=5;U=4
Sc2/80 20 . A T 86 Pass N=2 F=5;U=4
Sc2/80 20 . A C 80 Pass N=2 F=5;U=4

Logic: All the even lines of the input file should be compared and ranked according to the score (Descending Order) and the corresponding odd line of the file should be printed as well with it. If any of the scores (of the even lines) are equal then we need to look at the score of the corresponding odd line and therefore, the higher score gets priority and is printed first.

share|improve this question
    
This seems related to some DNA (AGCT). Is it really related to DNA of some kind? –  Kartik Aug 8 '13 at 15:32
    
@Kartik : Yes, you are right. This work is a part of genome data analysis. –  Namrata Aug 13 '13 at 16:02

1 Answer 1

up vote 7 down vote accepted

A possible solution is to get each two lines together, sort, then split again the joined lines

awk '{ getline line; print $0, line }' input_file | 
    sort -k6,6nr -k15,15nr | 
    awk '{ $10 = "\n" $10; print }'
share|improve this answer
    
Thanks you very much. It works. It was of great help. –  Namrata Aug 7 '13 at 12:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.