sort in cygwin

Posted on 2009-04-24
Last Modified: 2013-11-15
A very simple example that I don't understand.

A file test.txt contains two records:


I use the following command to sort:

sort -t"|" test.txt

and the result is:


how come?

Question by:goph9998
    LVL 58

    Accepted Solution

    If you don't specify the key to sort on, the whole line is compared.

    sort -t"|" -k1,1

    info sort

    has a good description of it.

    Author Comment

    if I change "|" to ":" it works
    LVL 58

    Assisted Solution

    That is because it is sorting the while line. The field separator doesn't matter.

    When you compare


    the first characters that are different is X and | and between those X < |

    but when you compare


    the first character that are different are X and : and between those X > :

    ASCII(':') - 58
    ASCII('X') - 88
    ASCII('|') - 124

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
    In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
    This video shows how use content aware, what it’s used for, and when to use it over other tools.
    The viewer will learn how to back up with the free utility from runtime software, DriveImageXML using Windows 7. Download DriveImageXML from Open folder where it was saved: Start installation by double clicking the install scrip…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now