Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Scanning a file for a match, printing different part of the line when found.

by philipbailey (Chaplain)
on Mar 26, 2011 at 19:42 UTC ( #895691=note: print w/replies, xml ) Need Help??


in reply to Scanning a file for a match, printing different part of the line when found.

You can do this sort of thing with a one-liner. You don't specify what you want to match in much detail, but here is an example:

perl -ne 'print "$1\n" if /Name:\s*(.+?)\b/' search.txt
  • Comment on Re: Scanning a file for a match, printing different part of the line when found.
  • Download Code

Replies are listed 'Best First'.
Re^2: Scanning a file for a match, printing different part of the line when found.
by ww (Archbishop) on Mar 26, 2011 at 20:21 UTC
    Since OP wasn't specific about how "Name" is constructed, ++

    But note that this will not satisfy the op by printing the (whole) name field, if "Name" is comprised of more than one word (for example: Firstname MI Lastname), because of the \b

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://895691]
help
Chatterbox?
[holli]: And this guy was also Anti-Vaxx and I just snapped. I shoed him all over the yard
[james28909]: biting between the legs? now thats my kind of religion.
[holli]: and back into the building, saw him later peeking out of the window looking scared. It was hilarious.
[LanX]: Let's get physical...
[james28909]: wish i could stay and chat. i have an unsuspecting client to give an estimate to. muhhahaha

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (16)
As of 2017-12-13 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (373 votes). Check out past polls.

    Notices?