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

sort field when numeric value has a '+' or a '-'

Status
Not open for further replies.

arunrr

Programmer
Oct 2, 2009
103
0
0
US
Hello,

I have the following input file...

DCF,1,1,0,0,0,2,+7.620,72-8.0,69-50.0
AQP,1,1,0,0,0,2,+1.820,262-50.0,171-50.0
PMC,1,0,1,0,0,0,-1.820,171-50.0,262-50.0
BCI,1,1,0,0,0,2,+4.200,332-50.0,122-50.0
ZWA,1,1,0,0,0,2,+4.100,317-50.0,112-50.0
IMT,2,0,2,0,0,0,-4.897,181-100.0,389-58.0
OLU,1,0,1,0,0,0,-4.200,122-50.0,332-50.0

sort field separator is ","

I need to sort first using field 7 and then by field 8. However the "+" and "-" in field 8 does not provide the desired result when i use the following...

cat file | sort -t, -nr -k7,8

Thanks
AR
 
Never mind, the followed solved it...

cat file | sed -e 's/,+/,+,/' -e 's/,-/,-,-/' | sort -t, -nr -k7 -k9 | sed -e 's/+,/+/' -e 's/-,//'

Thanks
AR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top