[SOLVED] Which combination of commands to use for sorting and cutting?
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.
welcome to LQ. We will not do your homework for you. We will however help. So, what have you tried? What command line tools have you been taught about?
Nope. You can't cut a column, you have to keep the input all together. sort has an option to select the field to sort (see -k) and another one to specify the field separator (see -t). Try them out.
Okay. I had seen the -t option in the help for sort, but wasn't sure how to use it. But, sort command can be used to specify the field which needs to be sorted while also choosing the delimiter. For the above problem,
Could be the shell. Another way to do it is to use the -k option which defines the key, as colucix pointed it out above. So,
sort -n -t, -k5 PetTable | cut -d, -f1
works too. The -t option for sort works same as the -d option for cut. The character immediately following both options will define the delimiter. And -k option for sort seems same as -f option for cut. So, the digit immediately following them will be worked upon.
chrism01, can you please show how it can be done using grep command?
Last edited by HaydeezPluto; 11-23-2012 at 05:17 PM.
hmmmm ... not to nitpick, but as chrism01 pointed out, your original question asked for the dogs to be sorted by weight and according to your input, Jamesbond is a goldfish and Gus is a turtle.
Should there not be more to your script to make this correct?
The "+n" style syntax in core commands like sort, head, and tail is generally deprecated, and may not be fully supported.
The gnu versions of these utilities used in Linux also often have differences from the versions available in other Unixes. Most of these are simply expansions and improvements, but sometimes the original *nix or posix syntax needs to be explicitly enabled.
In short, don't just trust any examples you get off the web. Always check the documentation (man and info pages) and make sure the command is fully compatible with the program you're using.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.