Hope this isn't too often repeated question with glaringly obvious
answer:
How to print only what a regex hits from a file, not the whole line.

IMPORTANT: I don't want techniques involving call back (remembered)
operators and parens, I know how to piece those together for simple
things like the file below.

Is there not a straight forward way to make perl print only what a
regex sees?  I'm thinking of someting along the line of gnu awk
(gawks) ability to do it, as in defining RS (record separator) to a regex
then printing its content which appears in the builtin RT.
(example of awk below this example file)
 
Example file:
cat file

a line of print
a line of text
a line of blab
a silly line of print
a line of text
a silly line of blatterscat
a line of nonsense
a line of pure intellect

What perl code will go thru this file and print only what is hit by
regex /silly/?


Using the awk I mentioned and barring odd blanks one gets from
redefining the RS:
 awk 'BEGIN{RS="silly"}{print RT}' file
 silly
 silly
 <blank line> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to