in reply to Parse the text file output and delete files

Just parse your file once and only forward.

Keep track in a variable at all time of the last executing: @ ... dir1.sql encountered, and, when you meet an ERROR line, you know that you can delete the SQL file whose name is in the last-sql-file variable (if the file still exists).

No need to read backward.

Replies are listed 'Best First'.
Re^2: Parse the text file output and delete files
by Gaurav99 (Initiate) on Jul 20, 2015 at 16:59 UTC
    I am very new to perl.Will really appreciate if I have the script for the logic above.

      I would explore the tutorials you can find here. Or google "perl basic file operations". Make some effort - you'll learn more that way!

      Dum Spiro Spero
      Hi,

      the general basic idea might perhaps be something like this:

      my $last_sql_file; while (my $line = <$LOG>) { chomp $line; $last_sql_file = $1 if $line =~ /^executing: \@(.+)/; if ($line =~ /^ERROR at/) { unlink $last_sql_file if -f $last_sql_file; # don't try to del +ete this file if it was already deleted on a previous error } }
      That's the basic algorithm, please fell free to ask if you don't understand it. I leave it to you to find out in the documentation how to open the log file if you don't know how (clue: take a look at open).