I am trying to find a way to read a log file looking for a key word and return text from the log associated with that key word. Big issue is that the log file updates dynamically and is cleared every 24 hours. So If I look for keyword "101", I will get all of them since last night, where what I need is just the ones since my last check/poll.
Example log: 101 QE300800 0AAAAAAAAAAABEU5 TAERP060_600 TESTCOS 589854 5 TAERP060_600 maestro TAERP060\040PRIORITY(5)\040CPDEPR(N) -32768 1 2011110306000000 0 +++ 879 0 1320300000 1320300000 180 0 2 0AAAAAAAAAAABEU5 879 DET_M-S_1 2011110306000000 v.4 NONE NONE 4 NONE NONE NONE 0 0 0 0 0 NONE
I need the "TAERP060_600" and the next one too. How do you grab the data, then, how do you make sure you get them all but no duplicates? Any help is MEGA appreciated!!!!! So far I have the keyword search and thats all.... I know... lame....
perl ${SCRIPT} /tws/dv/event.log "101 " #!/usr/bin/perl -s if (@ ARGV[0] =~ /\bhelp\b/) { print "Usage: KeywordSearch.pl <path>\/filename> <pattern>\n"; exit 1; } chomp($file = @ ARGV[0]); chomp($pattern = @ ARGV[1]); if (length($file)==0||length($pattern)==0){ print "Message: Bad argument! Please see help\n"; print "Statistic: 0\n"; exit 1; } else { if (!-e $file){ print "Message: \"$file\" (File NOT FOUND!)\n"; print "Statistic: 0\n"; exit 1; } } open (F, '<', $file) || die $!; my @lines = <F>; foreach my $line (@lines) { if ($line =~ /\Q$pattern\E/) { print "Message: \"$pattern\" (Pattern FOUND)\n"; print "Statistic: 1\n"; exit 0; } } print "Message: \"$pattern\" (Pattern NOT FOUND)\n"; print "Statistic: 0\n"; exit 0
In reply to Returning data from a log file by familyofcrowes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |