Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Duplicating default behavior of unix sort

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Duplicating default behavior of unix sort

    Unix sort uses en_US.UTF-8 by default.

    I'm trying to find a Locale and Collator that will duplicate the way that unix(linux) sort works by default.

    Does anyone have any ideas?

    Thanks much.

    sl73caeapp03:~ $ cat f
    a
    A
    b
    B
    sl73caeapp03:~ $ sort f # how to duplicate this behavior?
    a
    A
    b
    B
    sl73caeapp03:~ $ LC_ALL=c sort f # not this behavior
    A
    B
    a
    b


    -dreamer


  2. #2
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: Duplicating default behavior of unix sort

    On my Centos 6.4 Linux system (installed with default US settings) the collator is POSIX.

    So...

    [Zaphod@star5x2 ~]$ locale
    LANG=en_US.utf8
    LC_CTYPE="en_US.utf8"
    LC_NUMERIC="en_US.utf8"
    LC_TIME="en_US.utf8"
    LC_COLLATE=POSIX
    LC_MONETARY="en_US.utf8"
    LC_MESSAGES="en_US.utf8"
    LC_PAPER="en_US.utf8"
    LC_NAME="en_US.utf8"
    LC_ADDRESS="en_US.utf8"
    LC_TELEPHONE="en_US.utf8"
    LC_MEASUREMENT="en_US.utf8"
    LC_IDENTIFICATION="en_US.utf8"
    LC_ALL=
    [Zaphod@star5x2 ~]$ echo $LC_COLLATE
    POSIX
    [Zaphod@star5x2 ~]$ cat f
    b
    a
    B
    A
    [Zaphod@star5x2 ~]$ sort f
    A
    B
    a
    b
    [Zaphod@star5x2 ~]$ export LC_COLLATE=en_US
    [Zaphod@star5x2 ~]$ sort f
    a
    A
    b
    B


    Cheers!

    Z

Similar Threads

  1. Duplicating array in C code
    By FearTheCron in forum Java Native Interface
    Replies: 1
    Last Post: April 6th, 2013, 10:33 PM
  2. JButtons behavior in ActionListener
    By QuincyOrsot in forum Object Oriented Programming
    Replies: 3
    Last Post: April 26th, 2012, 04:00 PM
  3. What is the best way to avoid duplicating code?
    By Kerr in forum Object Oriented Programming
    Replies: 9
    Last Post: December 1st, 2011, 09:24 AM
  4. How to get unix timestamp from formatted date?
    By snytkine in forum Java Theory & Questions
    Replies: 5
    Last Post: October 12th, 2010, 09:07 AM
  5. duplicating output
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: January 3rd, 2010, 01:11 AM