[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!
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.
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 06: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.