Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Another way of looking at is that the sort command treats strings of numbers like strings of letters. It sorts them not according to their value but according to their postion in the "alphabet" (0-9 instead of a-z) in the way that smallpond described it. So 1025 comes before 125 for the same reason that bacf comes before bcf in normal alphabetization.
Hope that's clear.
As you've been told three times already, it sorts it alphabetically. 1 comes before 2, 2 comes before 3, etc. It does this on individual characters, NOT on the entire number. If two lines start with the same character, it moves to the second character, then the third, same way you alphabetize any list.
Start by just looking at the first character
$ sort file5
Ok, there are three 1s, so move to the next character and what do you get
How about the 2s
And the 456s are the same, so their "order" doesn't matter.
Last edited by suicidaleggroll; 04-10-2014 at 02:45 PM.
Hi All ;
Clearly i have posted , what is the logic behind for my output . I am NOT asking abt -n option. Please provide answers for my EXACT Question
Please READ AND UNDERSTAND the answers you have been given. smallpond, suicidaleggroll, and jdkaye have ALL told you exactly why you're getting that output. You were also pointed to the man page, and as far as I know, there is NOTHING keeping you from going to Google and doing further research, or even downloading the source code for sort and looking at it.
If you don't like the answers you get here, you can always ask elsewhere...perhaps they can fit your 'exact' needs. If you don't UNDERSTAND the answers you get here, being snotty sure won't get you much further.
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
It used to be called "sort-merge". That should explain the internal logic to you. This can be another thread. Briefly the `sort` command assumes line by line left to right character based sorting unless you give options. The `man` says it simply. "SORT LINES OF TEXT FILES".
You really should READ THE MANUAL.
SO AS OTHERS HAVE SAID REPEATEDLY, UNLESS YOU USE OPTIONS, SORT ASSUMES THAT THE LINES TO BE SORTED ARE CHARACTERS. UNLIKE NUMBERS AND DIGITS, THE ASCII VALUE USUALLY DETERMINES THE SEQUENCE.
You can use options to change the column delimiter, column number and nature of data to be sorted.
Where the second line is the octal value for each byte of the input.
Sort uses the values from the second line to sort by. And doing that means that 060 (the second byte of the first line) is less than 062 (the second byte of the second line), thus the first line is placed first.
Using the -n option to sort causes sort to first convert the data into integers.