1

I am working on a file that contains the following format:

R      |  CF    |  PN    |  seq          |  UC  

801    |  10    |  P3    |  643455423    |  C1    
804    |  11    |  P1    |  643455427    |  C1    
804    |  11    |  P1    |  643455427    |  C5    
802    |  11    |  P2    |  643455431    |  C1    
800    |  11    |  P2    |  643455429    |  C2    
800    |  11    |  P2    |  643455429    |  C2    
802    |  11    |  P2    |  643455431    |  C2    
800    |  11    |  P3    |  643455423    |  C1    
804    |  11    |  P3    |  643455433    |  C2    
802    |  11    |  P3    |  643455425    |  C3    
804    |  11    |  P3    |  643455433    |  C3    
802    |  11    |  P4    |  643455425    |  C2    
801    |  12    |  P1    |  643455424    |  C2    
801    |  12    |  P1    |  643455424    |  C2    
805    |  12    |  P1    |  643455434    |  C2    
805    |  12    |  P1    |  643455434    |  C3    
805    |  12    |  P3    |  643455428    |  C1    
805    |  12    |  P3    |  643455428    |  C1    
801    |  12    |  P3    |  643455430    |  C3    
803    |  14    |  P1    |  643455432    |  C1    
803    |  14    |  P1    |  643455432    |  C1    
803    |  14    |  P2    |  643455426    |  C1    
803    |  14    |  P2    |  643455426    |  C3    
801    |  19    |  P4    |  643455430    |  C3    

I am trying to group lines by the most ressemblece (Greatest-Common-Divisor like) by those three columns.
That means if two lines or more share the same CF-PN-UC values, they should be grouped, if not so, those who shares the same CF-PN should be grouped, but if not, the rest must be grouped by the CF.

Is there a way that i can get the following as result?

R      |  CF    |  PN    |  seq          |  UC  
#CF
801    |  10    |  P3    |  643455423    |  C1  
#CF-PN
804    |  11    |  P1    |  643455427    |  C1    
804    |  11    |  P1    |  643455427    |  C5       
#CF-PN-UC
800    |  11    |  P2    |  643455429    |  C2    
800    |  11    |  P2    |  643455429    |  C2    
802    |  11    |  P2    |  643455431    |  C2    
#CF-PN
800    |  11    |  P3    |  643455423    |  C1    
804    |  11    |  P3    |  643455433    |  C2    
#CF-PN-UC
802    |  11    |  P3    |  643455425    |  C3    
804    |  11    |  P3    |  643455433    |  C3  
#CF
802    |  11    |  P2    |  643455431    |  C1  
802    |  11    |  P4    |  643455425    |  C2    
#CF-PN-UC
801    |  12    |  P1    |  643455424    |  C2    
801    |  12    |  P1    |  643455424    |  C2    
805    |  12    |  P1    |  643455434    |  C2    
#CF-PN-UC
805    |  12    |  P3    |  643455428    |  C1    
805    |  12    |  P3    |  643455428    |  C1  
#CF
805    |  12    |  P1    |  643455434    |  C3 
801    |  12    |  P3    |  643455430    |  C3    
#CF-PN-UC
803    |  14    |  P1    |  643455432    |  C1    
803    |  14    |  P1    |  643455432    |  C1    
#CF-PN
803    |  14    |  P2    |  643455426    |  C1    
803    |  14    |  P2    |  643455426    |  C3    
#CF
801    |  19    |  P4    |  643455430    |  C3 

Thanks for Your Help.

| improve this question | | | | |
3

This is just a sorting problem:

head -2 input.file; tail -n +3 input.file | sort -t '|' -k2,2n -k3,3 -k5,5

That means: "Sort by column 2 numerically. In the case of a tie, sort by column 3. In the case of a tie, sort by column 5.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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