Link to home
Start Free TrialLog in
Avatar of David Aldridge
David AldridgeFlag for United States of America

asked on

Sorting two columns in a csv file

What is the best way to sort on two columns in a .csv file? Here is an example:

serverone, a1
serverone, cpu
serverone, a2
servertwo, cpu
servertwo, a2
servertwo, a1
etc....

What I would like to do is sort it like so:

serverone, a1
serverone, a2
serverone, cpu
servertwo, a1
servertwo, a2
servertwo, cpu
etc...

I got the first column using 'sort', but can't figure out the best way to sort the second.

Thanks!
David
Avatar of Frosty555
Frosty555
Flag of Canada image

You could concatenate the contents of the two columns together and sort on that.

Or, probably the more correct thing to do would be to perform your comparison on the first column, just like you're doing now, but in the event that they are equal, do a comparison on the second column as the tiebreaker.
ASKER CERTIFIED SOLUTION
Avatar of Frosty555
Frosty555
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David Aldridge

ASKER

Ozo is absolutely correct. After doing some more research, I found out that I had some corrupted data in the csv file which was causing the problem. I apologize for wasting everyone's time. I think the fair thing is to split the points between the four responders.

Thanks everyone,
David