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.
Sorry, what's the point of this thread? Just use awk.
not programming. Moved to Linux - Newbie.
It's philosophy about cut.
Awk is not a wise solution if for instance you code an application over sh and give it to a friend. If he has not awk, what you do? however all alternative to cut are done with some packages that may not be installed...
Besides acid_kewpie's comments: The cut command _does_ work! The problem is that the output of ls is space(s) separated and cut uses a tab as delimiter....
Using awk is the best/easiest solution in this case. I haven't come across a linux/unix distro that does not come with awk, if the actions done with awk are simple it doesn't matter if nawk, gawk, mawk or Xawk is used.
this is slightly off topic from your initial post, but your second post you indicate that your motivation for the question is portability.
If you want portability, I'd suggest not parsing the output of ls. The output of 'ls -ltra' can differ significantly on different systems. Since you mention 'cut -f3' I guess you are trying to get a list of the file owners (at least that is the 3rd field on my system).
For ps aux, it is the same story, it is not working also for portability:
ps aux | cut -f4
Solution is surely awk that is likely installed but if you take a 300MB just installed debian for instance (server install with the minimum) you will not have awk at all, nor perl. However "cut" is there, but it cannot easily crop the columns
this is similar to my post suggesting you use stat.
Originally Posted by frenchn00b
For ps aux, it is the same story, it is not working also for portability
I'd suggest that the solution with ps, is not to parse its output (with cut, awk, perl or whatever), but to give the correct flags/options to ps so that it only ouputs the information that you are interested in.