Welcome to WebmasterWorld Guest from 188.8.131.52 , register , login , search , subscribe , help , library , PubCon , announcements , recent posts , open posts Pubcon Website
Unix sorting on multiple fields JohnKelly msg:4117087 8:07 pm on Apr 16, 2010 (gmt 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?
lammert msg:4117476 10:35 pm on Apr 17, 2010 (gmt 0)
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 msg:4118526 2:48 am on Apr 20, 2010 (gmt 0)
That works, thanks!