Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: One Liner, print multiple regex matches

by toolic (Bishop)
on Nov 16, 2012 at 21:45 UTC ( #1004250=note: print w/ replies, xml ) Need Help??


in reply to One Liner, print multiple regex matches

Add quotes around $1 and $2:

perl -nle ' print "$1 $2" if /name=(\w+).*age=(\d+)/' filename

warnings can also be used with one-liners to help you debug:

perl -nlew ' print $1 $2 if /name=(\w+).*age=(\d+)/' filename Can't open print $1 $2 if /name=(\w+).*age=(\d+)/: No such file or di +rectory.

Please update your post to add "code" tags around your input file data.


Comment on Re: One Liner, print multiple regex matches
Select or Download Code
Replies are listed 'Best First'.
Re^2: One Liner, print multiple regex matches
by cipher (Acolyte) on Nov 16, 2012 at 22:24 UTC
    Thank's It worked!

    I simply added the quotes and its showing data for both regex matches.

    Working code:
    perl -nle ' print "$1$2" if /name=(\w+).*age=(\d+)/' filename

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004250]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (15)
As of 2015-07-31 15:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls