Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort 2d histogram data smallest to largest

Status
Not open for further replies.

programmerc

Programmer
Oct 29, 2010
10
GB
I've got 2D histogram data output


6.5 -1.25 10.2804
6.5404 -1.25 10.4907
6.58081 -1.25 10.8087
6.62121 -1.25 10.4686
6.66162 -1.25 10.506
6.70202 -1.25 10.3084
6.74242 -1.25 9.68256
6.78283 -1.25 9.41229
6.82323 -1.25 9.43078
6.86364 -1.25 9.62408
6.90404 -1.25 9.23871
6.94444 -1.25 9.4298
6.98485 -1.25 9.42173
7.02525 -1.25 9.45413
7.06566 -1.25 9.2722
...
6.5 -1.21717 10.3285
6.5404 -1.21717 11.1678
6.58081 -1.21717 10.8977
6.62121 -1.21717 10.8864
6.66162 -1.21717 10.3389
6.70202 -1.21717 9.96492
6.74242 -1.21717 10.4141
6.78283 -1.21717 10.1318



I need to sort the data in both X and Y column simultaneously, to get ordered pairs (X,Y) from smallest to largest.

sort -k1,1n -k2,2n inputdata.dat
did not work
 
how should the result (for the data above) look like ?
 
It should be min(X,Y) to max(X,Y)

6.5 -1.25 10.2804
6.5 -1.21717 10.3285
etc

No value must decrease in subsequent records. I need the data in R which requires incremantal X, Y ordering.
 
Currently the data decreases in periodic repetition


6.5 -1.25 10.2804
6.5404 -1.25 10.4907
6.58081 -1.25 10.8087
6.62121 -1.25 10.4686
6.66162 -1.25 10.506
6.70202 -1.25 10.3084
6.74242 -1.25 9.68256
6.78283 -1.25 9.41229
6.82323 -1.25 9.43078
6.86364 -1.25 9.62408
6.90404 -1.25 9.23871
6.94444 -1.25 9.4298
6.98485 -1.25 9.42173
7.02525 -1.25 9.45413
7.06566 -1.25 9.2722
...
6.5 -1.21717 10.3285
6.5404 -1.21717 11.1678
6.58081 -1.21717 10.8977

6.62121 -1.21717 10.8864
6.66162 -1.21717 10.3389
6.70202 -1.21717 9.96492
6.74242 -1.21717 10.4141
6.78283 -1.21717 10.1318


I need to sort simultaneously X and Y to get rid of this order.
 
I tried:
Code:
$ export LC_ALL=C
$ sort -k1 -k2 -n inputdata

and got the data sorted:
Code:
6.5 -1.25 10.2804
6.5 -1.21717 10.3285
6.5404 -1.25 10.4907
6.5404 -1.21717 11.1678
6.58081 -1.25 10.8087
6.58081 -1.21717 10.8977
6.62121 -1.25 10.4686
6.62121 -1.21717 10.8864
6.66162 -1.25 10.506
6.66162 -1.21717 10.3389
6.70202 -1.25 10.3084
6.70202 -1.21717 9.96492
6.74242 -1.25 9.68256
6.74242 -1.21717 10.4141
6.78283 -1.25 9.41229
6.78283 -1.21717 10.1318
6.82323 -1.25 9.43078
6.86364 -1.25 9.62408
6.90404 -1.25 9.23871
6.94444 -1.25 9.4298
6.98485 -1.25 9.42173
7.02525 -1.25 9.45413
7.06566 -1.25 9.2722
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top