The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 04-28-2008
quine quine is offline
Registered User
  
 

Join Date: Mar 2008
Location: Bay Area California
Posts: 68
Two approaches....

1. Search for any of the words on each line and every time you find one, add it to a hash... e.g. $somehash{"Renaldo"} = 1;

When you've finished scanning the whole file, check the resulting hash for the existence of all the words....

if (exists $somehash{"Renaldo"} && exists $somehash{"loosers"} && exists ... ) { send email ... }

Something like that....

OR....

You could try a pattern like

$FILEBUFFER =~ /(A|B|C|D).+(A|B|C|D).+(A|B|C|D).... /is

You simply repeat the alternatives over and over again separated by one or more of any character, and that way you catch all of them if present no matter what the order.... You have to test the resulting capture to see if all words are present... Note the "is" at the end of the pattern... "i" causes case to be ignored, and "s" says to count a newline as one of the "any characters" which lets you match across lines... Note that in this case $FILEBUFFER contains the WHOLE file (see READ()), not a line....