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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting 4

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
I need to sort columns by numbers (in brackets as in example below) first by 2nd column, next by 3'rd column.

Example input file contains:

Code:
 q1(4.3) qp(8) q2(1.1)
q1(2.3) qp(8) q2(5.6)
q1(6.2) qp(8) q2(6.1)
q1(0.5) qp(2) q2(0.9)
q1(1.7) qp(2) q2(3.8)
q1(0.7) qp(2) q2(3.2)
q1(13.1) qp(8) q2(15.6)
q1(4.3) qp(8) q2(14.0)
q1(1.5) qp(8) q2(1.3)
q1(1.3) qp(2) q2(24411710)
q1(0.8) qp(2) q2(21829714)
q1(3.6) qp(2) q2(8.9)
q1(1.8) qp(2) q2(7.2)
q1(0.1) qp(2) q2(0.2)
q1(4.7) qp(8) q2(2.3)
q1(1.5) qp(8) q2(2.1)
q1(3.5) qp(8) q2(2.8)
q1(1.8) qp(8) q2(2.7)
q1(0.1) qp(2) q2(0.1)
q1(0.1) qp(2) q2(0.2)
q1(4.2) qp(8) q2(33546628)
q1(0.4) qp(2) q2(1.0)
q1(0.3) qp(8) q2(0.4)
q1(0.6) qp(8) q2(0.1)
q1(0.3) qp(2) q2(0.9)
q1(0.6) qp(8) q2(0.0)
q1(0.9) qp(8) q2(4.0)


thx in advance,
R.
 
Hi

As far as I know, you can not solve it in one step. At least not with the [tt]sort[/tt] tool.
Code:
sed 's/.*(\(.*\)).*(\(.*\)).*(\(.*\)).*/&|\1|\2|\3/' /input/file | sort -n -t '|' -k 3 -k 4 | sed 's/|.*//' > /output/file


Feherke.
 
Have you tried this ?
sort -n -t '(' -k 3 -k 4 /path/to/input

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thx!

Both ways do the job. Outputs are identical.

$ cksum /tmp/result_feherke /tmp/result_PHV
1612755326 7283 /tmp/result_feherke
1612755326 7283 /tmp/result_PHV


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top