Couldn't find much help on the kind of question I've here:
There is this text file with text as:
Line one has a bingo
Line two does not have a bingo but it has a tango
Bingo is on line three
Line four has both tango and bingo
Now I would want to search for the pattern "bingo" in this file and split the line to extract the words immediately preceding and following - "bingo".
Tried with this script using perl.. but my output file shows no result.
#! /usr/bin/perl
open (INFILE, "text1.txt");
open (OUTFILE,">outtext1.txt");
while (<INFILE>)
{
if (s/\w*(\w{1})bingo(\w{1})\w*/\1\2/) {
print OUTFILE;
}
}
close (INFILE);
close (OUTIFLE);
WIth this expression, I expect to get atleast the 2nd line to pass and the output file to have a but ['a bingo but']. But I get an empty outfile.
Can someone please point out how to accomplish this?
Thanks!