Hello Perl Monks, I have an issue with regular expressions and matching. I have a text file of the format given below.
C:\EITV10CM\base\repair\Companion_Repair\File2File\F2F.COM ... is OK. C:\EITV10CM\base\repair\Companion_Repair\File2SelfExt\F2SEXT.CMP ... i +s OK. C:\EITV10CM\base\repair\Companion_Repair\File2SelfExt\F2SEXT.COM ... F +ound the CMPAN/File2SelfExt virus !!! The virus has been removed from the file. Checking for another virus in the file ... C:\EITV10CM\base\repair\Companion_Repair\File2SelfExt\F2SEXT.COM ... i +s OK. C:\EITV10CM\base\repair\Companion_Repair\File2SelfFile\F2SFILE.COM ... + Found the CMPAN/FIle2SelfFile virus !!! The virus has been removed from the file. Checking for another virus in the file ... C:\EITV10CM\base\repair\Companion_Repair\File2SelfFile\F2SFILE.COM ... + is OK.
I have to write a perl script which accepts as an input a list of filenames possibly in an arraqy; for every filename in the array; i shud find a match in a text file as pasted above in the sample. There are cases where there can be multiple entries for the same filename in the text file. For example in the above sample file pasted C:\EITV10CM\base\repair\Companion_Repair\File2SelfExt\F2SEXT.COM is listed twice. Ihave to extract the first occurence of the filename in the text file which matches the filename in the array and extract out the remaining statement i.e Found xxxxxxx. I did try a piece of code...but i am not able to match the same. Could you please help me fix this problem. Here is the piece of code that i tried out.
#!/usr/bin/perl #!/usr/bin/perl #Program to read the command line report file; and extract the virus d +etection name for a file. $cmdrep = "d:/eitv10cm_cln.rep"; open FH, "<$cmdrep" or die "Cannot open $cmdrep. \n"; $fname = "C:\EITV10CMD\base\detection\basic_detection\Filename\DOIFFIL +E.COM"; while (<FH>) { chomp; if($_ =~ /^$fname/i) #Instead $fname tried giving C:\EITV10CMD\bas +e\detection\basic_detection\Filename\DOIFFILE.COM. { chomp($_); /\s(\.){3}.*?)$/; #Trying to extract everthing after ... $found = $1; } if ($found eq "is OK.") { $virusname = "OK"; print "The virus detection name is $virusname\n"; } if ($found =~ /^Found: (.*?) NOT a virus[.]/) { $virusname = $1; print "The virus detection name is $virusname\n"; } elsif ($found =~ /^Found the (.*?) (virus|trojan) !!!/) { $virusname = $1; print "The virus detection names is $virusname\n"; #exit(); } elsif ($found =~ /^Found potentially unwanted program (.*?)[.]/) { $virusname = $1; print "PuPs $virusname \n"; } elsif ($found =~ /Found (virus or variant|application) (.*?)( !!!| +[.])/) { $virusname = $2; print "virus or variant $virusname \n \n"; } }
Thanks, Nisha

In reply to Matching and extracting from file. by nisha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.