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.
I don't know if I'm doing something wrong here, but sed appears to be not working properly on my system. I tried a number of examples from Rute (asper my sig.) and whenever I try a sed command of the the 'sed -e 's/>regexp>/<substitution>/g' type nothing happens.
I tried the following command:
Code:
$ ls -l | grep ^-| sed -e 's/^\(<.*> [ ]*\){8}\(.$\)/\2/g'
It is supposed to return 'clean' filenames. The only thing I get is the ls -l output without any directories, but with full permission, owner, time etc info. I've asked other people to try the command and they tell me it works. What might be going wrong?
1. Well, the books ben around for +10 years and has been updated, plus it's used by quite some institutions to teach linux courses, so somebody might have noticed before now...
2. info sed has a lot of info, but i'm looking for a tutorial, something with practical examples to see what happens (or should happen). It's just the way I learn best
Wheyhey, that works! (that's what I meant with 'clean' filenames) Thanks.
But why does it work? Why doesn't it return 'linmix' as well if the ls -l output is '-rwxr-xr-x 1 linmix linmix 232 Dec 2 22:35 test.sh'
Regular expression generally do what's knwon as "greedy matching" - they match as much as they possibly can. In the command above, sed will match zero or more occurrences of any character followed by a space. Greedy matching will match to the last space it can find, which is the one preceding the filename. Greedy matching is also the main pitfall you have to guard against when constructing complex patterns.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.