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!

problems - sort

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Can anyone help me, I need to sort this file-

96000777 13 FAILED
96000999 43
Joan Bakewell 100
Albert Einstein 80
Brian Head MISSING
Slap Head MISSING
Catherine Maguire 40
Peter Scott 20 FAILED
Hilary Smith 60

So that it goes in surname alphabetical order, then lists the fields with no names afterwards ie-
Joan Bakewell 100
Albert Einstein 80
Brian Head MISSING
Slap Head MISSING
Catherine Maguire 40
Peter Scott 20 FAILED
Hilary Smith 60
96000777 13 FAILED
96000999 43

Thanks for any help
 
#!/bin/sh
cat <file> | grep -v '^[1234567890]' | awk '{printf(&quot;%s %s %s %s\n&quot;,$2,$1,$3,$4);}' | sort | awk '{printf(&quot;%s %s %s %s\n&quot;,$2,$1,$3,$4);}' > <file2>
cat <file> | grep '^[1234567890]' | sort >> <file2>

first sorts everything (second word and first are swapped before sorting, and swapped back afterwards) not beginning with a number, second sorts everything beginning with a number and cats it onto the end of the first.

could do it with one command, using gawk/awk, but that's harder
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top