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.
That does not work, I just get an empty output, even if FILE.TXT contains lines which fit the desired regexp :[
I've searched but did not found my way.
I'd like to do it with awk, as I want my program to rely only on awk, nothing else such as sed, grep, etc.
Thanks!
Cordially,
BlueSpirit
Last edited by BlueSpirit; 05-15-2011 at 12:48 AM.
Your regular expression should work. Are you sure there aren't leading spaces in the "dotted" lines? Please, can you post some lines of the input file?
I'm suspecting though that you're trying to parse the output of ls. If so, there are usually better ways to go about it.
Even if I'm wrong, if you tell us exactly what you're trying to accomplish, and give us an actual example of the input text, we may be able to give you some better advice.
David, I am parsing a file which contains lines issued by ls, but I cannot modify the way these lines are done since It's from a ftp listing...
I still have a question for you guys. Yesterday I didn't know yet how to use awk, now I'm not bad at all. I still have a question, only for curiosity. My current awk cmdline ensures I find a line which has $NF as a path conforming to the following model:
Code:
./filepath/filename.extension
The way I do this is:
Code:
awk '$NF~/^\..*\.extension$/{print $NF}' FILE.TXT
My question is: WOuld it be possible to add to this command line, i.e. in a single awk call, a call to the awk function sub? I'd like to do this:
Grail to the rescue again. I don't know why, but I seem to always have trouble with awk's bracket syntax, even in supposedly simple one-liners like this. So I usually end up being very conservative and spell out the if tests fully. Maybe one of these days I'll get it all figured out.
Just a small caveat. The first link is a commonly-recommended tutorial, but it's based on old unix versions of awk. Be aware that the gnu awk used in Linux has more features and a few other differences.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.