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