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

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.