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.
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:
Code:
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.
Quote:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.