in reply to script to grab string from log and print them in a different log

Hi perl_geoff,

It looks like the only thing left to do is print the matching lines to the output file:

while ( <LOG> ) { if ( $_ =~ /$MAL/i ) { # Grab all strings that contain this regex # Save them all in $out print OUT $_; }

Note that there's no comma "," after the file descriptor OUT.

Does that do what you want?

Update:  You don't need the final print OUT "$out"; of course.  Also, since the =~ operator works on $_ by default, you could simplify the line containing the regex match to:  if (/$MAL/) {.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: script to grab string from log and print them in a different log
by perl_geoff (Acolyte) on Feb 01, 2007 at 16:05 UTC
    Thanks, that helps but I am not sure how to write the logic for my commented out sudo code: # Grab all strings that contain this regex # Save them all in $out Thanks :)
      Oh, sorry ... didn't see that! :-/

      Try this:

      # Find lines starting with "_ and ending with ". my $MAL = '^"_.*"$';

      Read up on perlretut for a good beginning guide to regular expressions.


      s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
        OK, this is looking much better now...unfortunately it isn't printing anything in my backup.txt file... Here's what I have:
        use strict; use warnings; my $out = "Backup/backup.txt"; my $logfile="log.txt"; my $MAL = '^"_.*"$'; my $logfile_new; open LOG, "<", $logfile or die "Cannot open $logfile for read :$!"; open OUT, ">$out" or die "Cannot open $out for write :$!"; while ( <LOG> ) { if ( $_ =~ /$MAL/i ) { print OUT $_; } }
        Thanks :)