I am trying to write a script that searches for the string ERROR in a log and print that line as well as the line above it to a CSV file. However, I am not sure how to get the line directly above the error line to print.
Here is my code.
open (DIFFR, "/tmp/log.diff");
while (<DIFFR>) {
$line=$_; #read first line
chomp($line);
if ($line =~ /ERROR/) {
print CSVFILE "$line,";
}
The reason is that the ERROR line has pertinent info the line directly above it in the log file. Here is some sample data:
2004.12.01 20:00:49.307 Agent.AgentLOG saveToSYS_AGENT_RUN_LOG()
ourhost(10.10.52.36) ERROR: ********* memo == *** End Execution