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.
It's a problem with delimiters. "sort" uses space(or consecutive spaces) and "cut" uses tab. The chkconfig output has no tab between the program name and the first on/off field.
norobro: Thank you for your help. You are right, it is a matter of delimiters and your examples are great.
One can display hidden characters in a file with vi file and :set list (:set nolist). spaces are always displayed as spaces, tabs are displayed either as alignment (nolist), or as ^I (list).
chkconfig --list inserts both spaces and then tabs after names, either of them just fine for correct alignment.
sort splits fields between a non-blank character to the left and a blank character to the right. blanks are spaces and tabs. cut splits fields at tabs. What happens here is that all spaces and tabs after names in chkconfig --list are preserved by cut and assigned to the second field by sort. Therefore, when I sort -k2,2r, all "on" fields are not equal at all, they are sorted according to their leading spaces. The 'incompatibility' between cut and sort is that cut's delimiter is tab and therefore it assigns blanks to the left field, while sort's delimiter is space and it assigns them to the right one.
Last edited by doru; 07-25-2009 at 08:46 AM.
Reason: correction
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.