ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Thanks it works.Ill check it out if i can use this in my programme. I am trying to read a file which say has contents of ls -l in it,and extract the file names from it and add it to a database,so if a file name has spaces in it my script is failing.Ill try it out with cut.
EDIT: -f1,3 prints 1 and 3
-f1-3 prints 1 to 3
-f1- prints 1 to infinte got it thanks.
It would be nice to know how to do the same using awk and print a range of columns.
Like pixellany, I do assume a basic understanding of awk.
The command given:
- sets the output field and record separator (OFS and ORS) to NULL, which makes sure that all is printed on the same line.
- prints fields number 6 up to the last field (NF holds the last field) on one line,
- the print $NF "\n" prints the last field and a carriage return (thus making sure all entries are on their own line).
then by using -F":", the field numbers will be wrong.
Of course!! But then, why would anyone put ":" in filenames?
Seriously, many of the solutions that we come up with are not robust---you're one of the people that keeps people like me honest....
Sometimes the discussions in programming turn out to be "cleverness" contests---and the results---while educational---are not what you would want to use for "real work".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.