|
|
Question : Scan text for a specific word and print surrounding text
|
|
How do I print text found prior to a selected word?
Scanning text for all occurrences of word "submarine" and printing with 30 words (or n characters, if easier) before and after the word
blah blah blah submarine blah blah blah
|
Answer : Scan text for a specific word and print surrounding text
|
|
okay.
my $number_of=3; if($line=~ m/(\s[^\s]+){1,$number_of}\s(submarine)(\s[^\s]+){1,$number_of}\s/gis){ print "$&\n"; }
|
|
|
|
|