Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Sorting in groups

$
0
0
Hi,

I am looking at a slightly different sorting problem and I am not sure how to do it in bash.

I have the following input:

Code:

0                                                                                                                                                                                                                                                                             
0.181017                                                                                                                                                                                                                                                                     
0.181017                                                                                                                                                                                                                                                                     
0.0409129                                                                                                                                                                                                                                                                     
0.214896                                                                                                                                                                                                                                                                     
0.214896                                                                                                                                                                                                                                                                     
0.781925                                                                                                                                                                                                                                                                     
1.05696                                                                                                                                                                                                                                                                       
1.05696                                                                                                                                                                                                                                                                       
0.791026                                                                                                                                                                                                                                                                     
1.10494                                                                                                                                                                           
1.10494                                                                                                                                                                           
2.04486                                                                                                                                                                           
9.37513                                                                                                                                                                           
9.37513
1.29588
15.6751
15.6751
15.873
19.2972
19.2972

I want to sort this, but in groups of three elements with the first one being the sorted value. For example line 16 is lesser than line 13 in the input and it must be re-sorted as the following. The two lines following the sorted value must be moved along with it.

Code:

0                                                                                                                                                                                                                                                                             
0.181017                                                                                                                                                                                                                                                                     
0.181017                                                                                                                                                                                                                                                                     
0.0409129                                                                                                                                                                                                                                                                     
0.214896                                                                                                                                                                                                                                                                     
0.214896                                                                                                                                                                                                                                                                     
0.781925                                                                                                                                                                                                                                                                     
1.05696                                                                                                                                                                                                                                                                       
1.05696                                                                                                                                                                                                                                                                       
0.791026                                                                                                                                                                                                                                                                     
1.10494                                                                                                                                                                           
1.10494                                                                                                                                                                           
1.29588
15.6751
15.6751
2.04486                                                                                                                                                                           
9.37513                                                                                                                                                                           
9.37513
15.873
19.2972
19.2972

Any pointers to do this is much appreciated.

Thanks!
Jamie

Viewing all articles
Browse latest Browse all 16232

Latest Images

Trending Articles



Latest Images