Welcome to WebmasterWorld Guest from 54.160.131.144

Forum Moderators: bakedjake

Message Too Old, No Replies

Unix sorting on multiple fields

     

JohnKelly

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

10+ Year Member



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?

lammert

10:35 pm on Apr 17, 2010 (gmt 0)

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



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

JohnKelly

2:48 am on Apr 20, 2010 (gmt 0)

10+ Year Member



That works, thanks!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month