Computing.Net > Forums > Unix > Perl one-liner parsing

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Perl one-liner parsing

Reply to Message Icon

Name: lamos
Date: November 9, 2007 at 09:56:45 Pacific
OS: UNIX
CPU/Ram: 2
Product: Solaris
Comment:


I've been trying to figure out how this Perl one-liner is suppose to work: perl -ne 'print "$1\n" if /rule\s\d/'

It's not working. It suppose to locate the word "rule" in the log file and output the rule # next to the word “rule” as listed in the URL.

http://www.brandonhutchinson.com/Ch...

Thank for your help.



Sponsored Link
Ads by Google

Response Number 1
Name: FishMonger
Date: November 9, 2007 at 16:24:09 Pacific
Reply:

I'd need to see some example lines from your log file, but off hand I'd say the problem is that you're not using any quantifiers and you're not using parens to capture your data.

Try this:

perl -ne 'print "$1\n" if /(rule\s+\d+)/' file.log


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Perl one-liner parsing

Issues with my UNIX Script www.computing.net/answers/unix/issues-with-my-unix-script/8469.html

editing files in Single User Mode www.computing.net/answers/unix/editing-files-in-single-user-mode/2067.html

concatenate strings www.computing.net/answers/unix/concatenate-strings/6153.html