use strict; use warnings; my @all_lines = <DATA>; # get the lines that match the word 'number' my @lines = grep /number/, @all_lines; print "Lines that matched\n"; print for @lines; # get and highlight the lines that match the word 'number' my @bold = map { $_ =~ /number/ and s/number/<b>number<\/b>/g ? $_ : ( +); } @all_lines; print "\nHighlighted word\n"; print for @bold; __DATA__ number.................... ..................... ......number.............. ......................... ..................number
outputs:
Lines that matched number.................... ......number.............. ..................number Highlighted word <b>number</b>.................... ......<b>number</b>.............. ..................<b>number</b>
In reply to Re: extract whole sentence after a match of a word
by olus
in thread extract whole sentence after a match of a word
by alkis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |