Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
Getting the program to sort $3 is easy enough but the trick is getting $1 and $2 into the output. With the sollution from that web site, $3 ends up in front of the others which I figured you wouldn't want so I added some more awk statements to get them back where they belong.
This will read file 2.dat, print the entire record, sort on field 3, print in numerical order (reversed), output to 2.dat, read from 2.dat.
It generates an error message (I haven't figured out why yet) about not being able to open file 2.dat, but it also sorts 2.dat, from largest to smallest value. To sort smallest to largest, remove -r from the above command.
So. Error message or no error message, the file gets sorted.
PS. The sort works fine without getting awk involved.
Last edited by bigrigdriver; 10-16-2004 at 07:14 PM.
This will read file 2.dat, print the entire record, sort on field 3, print in numerical order (reversed), output to 2.dat, read from 2.dat.
It generates an error message (I haven't figured out why yet) about not being able to open file 2.dat, but it also sorts 2.dat, from largest to smallest value. To sort smallest to largest, remove -r from the above command.
So. Error message or no error message, the file gets sorted.
PS. The sort works fine without getting awk involved.
First of all thanks for the answer it helped me.....but If you will change the command a bit than the Error message wont come. I have tried it myself.
The correct syntax would be.........
$ awk '{print $0 }' 2.dat | sort -t "|" -k 6 -n -r -o 2.dat 2.dat
that means don't put "$" in front of print option..............
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.