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!
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am able to sort a file by defining a starting column number in MSDOS. However I only know to sort a file through a field number in Linux. Is there any option in Linux to achieve what i have achieved through DOS. For example, I can say
sort /+21 filename
and this will sort using the info from column21 onwards of each line in the file. The reason for this is the number of fields in all the lines in the file to be sorted are not the same (output of a Fortran Program)
I have been using the -k option, but this is applicable when the lines are separated by fields delimited by field separator such as space or tabs. In my case the lines in my file have different number of fields, when the space is considered as a field separator. However the information that I want the sorting to be based upon are in the same column in each line, hence DOS sort does the job. However I want to know how to achieve this in LINUX if there is a proper option in sort. Since I could not find one, hence this post
KEYDEF is F[.C][OPTS][,F[.C][OPTS]] for start and stop position, where F is a field number and C a character position in the field; both are origin 1, and
the stop position defaults to the line's end. If neither -t nor -b is in effect, characters in a field are counted from the beginning of the preceding
whitespace. OPTS is one or more single-letter ordering options [bdfgiMhnRrV], which override global ordering options for that key. If no key is given,
use the entire line as the key.
Set the field separator so that the whole line is one field e.g. using the ASCII NUL
I have been using the -k option, but this is applicable when the lines are separated by fields delimited by field separator such as space or tabs. In my case the lines in my file have different number of fields, when the space is considered as a field separator. However the information that I want the sorting to be based upon are in the same column in each line, hence DOS sort does the job. However I want to know how to achieve this in LINUX if there is a proper option in sort. Since I could not find one, hence this post
You don't show any relevant example and do not mention why the given solution does not work.
The -k<number> (-k21) option tells sort to start sorting at column 21 (and everything after column 21 if needed!!).
The -k<number>,<number> (-k21,21) option sorts only column 21.
Without knowing what the input is like and how, exactly, you want this to be sorted we can only give you a global answer (which was given by Firerat).
Bingo!! The command sort -k1.n filename, where n is the column number worked fine though the number of blanks in the various lines are not the same. Thanks for the responses that I appreciate very much
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.