LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-07-2010, 09:31 AM   #1
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Sort generates unexpected results


Hello.

I sorted a large mailing list and the result is in almost sorted order, but not quite. The sort was invoked in the default manner, just "sort". See (below) a segment of the output file. (Note: the actual files have a street address following each name. I have omitted the addresses to avoid complaints about disclosing personal information on-line.)

I expect all people named KATZ to be grouped together, but they aren't. This phenomenon occurs elsewhere in the output file, so it has nothing to do with surnames beginning with the character string KATZ.

Please explain.

Daniel B. Martin

KATZ, ALISON B ~ 123 MAIN ST
KATZ, ARTHUR J ~ 456 MAIN ST
KATZ, CATHERINE AMMA ~ (et cetera)
KATZ, CHARLA EVANS ~ (et cetera)
KATZ, CHARLENE LOUISE ~
KATZ, CHLOE ALEXANDRA ~
KATZENBACH, DANIEL G
KATZENBACH, KEENA P
KATZENBERGER, HEATHER FOX
KATZENELSON, JONATHAN
KATZENELSON, SUSAN
KATZENMAIER, JONATHAN NIEL
KATZENMAIER, SUSAN ELIZABETH
KATZENSTEIN, LORI ARRINGTON
KATZENSTEIN, STEVEN DANIEL
KATZ, FRANCES T
KATZ, GEORGE
KATZ, GERTRUDE
KATZMAYR, CARISSA
KATZMAYR, LINDA BOZENBURY
KATZMAYR, PETER BRIAN
KATZ, MEGAN MURRAY
KATZ, MICHAEL D
KATZ, RACHEL LEEANN
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 06-07-2010, 09:45 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

This behavior is caused by your locale setting (see the sort man page).

LC_ALL=C sort file should work as you expect.

Hope this helps.
 
2 members found this post helpful.
Old 06-07-2010, 09:46 AM   #3
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
The default is sorting the entire line - not just the first field.

You can do field sort with:
sort -k1,1 -t,

The -k1,1 says to sort on the first field and the -t, says to use comma as the field separator.
 
1 members found this post helpful.
Old 06-07-2010, 07:23 PM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Original Poster
Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by druuna View Post
Hi,
This behavior is caused by your locale setting (see the sort man page).
LC_ALL=C sort file should work as you expect.
Hope this helps.
This works! Thank you!

Daniel B. Martin
 
1 members found this post helpful.
Old 06-07-2010, 07:23 PM   #5
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Original Poster
Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by MensaWater View Post
The default is sorting the entire line - not just the first field.

You can do field sort with:
sort -k1,1 -t,

The -k1,1 says to sort on the first field and the -t, says to use comma as the field separator.
This works! Thank you!

Daniel B. Martin
 
Old 06-08-2010, 02:39 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You're welcome
 
  


Reply

Tags
sort



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I do filtering in Perl (keep sort order and sort again by another means)? RavenLX Programming 9 12-19-2008 10:12 AM
find command displays unexpected results helptonewbie Linux - Newbie 5 08-12-2008 02:25 AM
Is there a line limit with the sort utility? Trying to sort 130 million lines of text gruffy Linux - General 4 08-10-2006 08:40 PM
php array sort inconsistent results rblampain Programming 2 04-03-2006 12:34 AM
pflogsumm generates zeroes for results rioguia Linux - Software 1 09-29-2004 03:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration