1748240 Members
3579 Online
108759 Solutions
New Discussion юеВ

Complex sort question

 
SOLVED
Go to solution
dbent
Occasional Contributor

Complex sort question

I want to sort a text file that includes an SSN and a dependent relationship code. This time, the dependent relationship (E for employee, D for Dependent) is in column 2, which needs to be sorted in reverse order after the SSN (columns 3-13). I have not found a way to reverse the sense of the comparision for one key, while keeping a normal comparison for the primary key.

A more complicated case that comes up involves ordering a family, so that the employee (e) is first, the spouse (s), is second, and the children (1,2,3,...) follow.

Thanks for looking
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor
Solution

Re: Complex sort question

Hi:

# sort -k2,2 -kr1,1 file

Regards!

...JRF...
dbent
Occasional Contributor

Re: Complex sort question

That worked! Big thanks!