homepage Welcome to WebmasterWorld Guest from 54.81.170.136
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved