Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Extract and print two specific keys and values using %

by kcott (Archbishop)
on Oct 31, 2017 at 07:30 UTC ( [id://1202399]=note: print w/replies, xml ) Need Help??


in reply to Extract and print two specific keys and values using %

G'day mao9856,

Welcome to the Monastery.

I see very little correlation between your title, data and code. Please see "How do I post a question effectively?".

Given this data:

$ cat pm_1202330_input.txt A B C . id “ABS0056”; D; E; F; G; name “SAM”; H; I; J; K; A B C . id “ABS0059”; D; E; F; name “JOE”; G; H; I; J; K; A B C . id “ABS0060”; D; E; F; G; name “MARY”; H; I; J; K; A B C . id “ABS0057”; D; E; F; G; H; name “BILL”; I; J; K; A B C . id “ABS0065”; D; E; name “RONIE”; F; G; H; I; J; K; A B C . id “ABS0061”; D; E; F; G; name “STEPHAN”; H; I; J; K;

You can get the output you indicate with this code:

$ perl -nle 'print /(id\s+\S+).*?(\sname\s+\S+)/' pm_1202330_input.txt id “ABS0056”; name “SAM”; id “ABS0059”; name “JOE”; id “ABS0060”; name “MARY”; id “ABS0057”; name “BILL”; id “ABS0065”; name “RONIE”; id “ABS0061”; name “STEPHAN”;

Note: I've used exactly the data you posted. Quotes have not been changed.

— Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 21:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found