Welcome to WebmasterWorld Guest from 54.196.232.162

Forum Moderators: bakedjake

Message Too Old, No Replies

Unix sorting on multiple fields

     
8:07 pm on Apr 16, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Oct 7, 2003
posts:539
votes: 0


I have flat file database delineated with the pipe symbol. I need to sort on the 8th field (province) and then the 7th field (city), so that the output will have the provinces in alphabetical order, and then the cities. Here is the code I'm using:


sort -t\| +7f +6f hotels_CA_only.txt > hotels_CA_only_sorted_by_province_then_city.txt


This seems to sort by province only but not city. What am I doing wrong, please?
10:35 pm on Apr 17, 2010 (gmt 0)

Senior Member from KZ 

WebmasterWorld Senior Member lammert is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 10, 2005
posts: 2886
votes: 1


Which Unix flavor or Linux distribution do you use? On Centos 5, the sort command needs the following parameters for this task:

sort -t\| -k8 -k7 input.txt > output.txt
2:48 am on Apr 20, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:Oct 7, 2003
posts:539
votes: 0


That works, thanks!