Monks of wisdom,

I have 2 scripts both are functional however I want to integrate the 2 into 1. I want the grep script to run inside the timesearch script. Both of the scripts follow below. I've tried to integrate them and almost had it. It would return a result of what I wanted but only one and not the rest of them. Here are the 2 scripts I mentioned below. The first script is the "grep" script.

#!/usr/bin/perl #This script will "grep" for msisdn's originating and destination and +transaction numbers for the MXE LOGS or#"mon402.log" chomp($key = <STDIN>); open(FILE, "mon402.log"); while (<FILE>) { foreach (sort {$a <=> $b} grep /$key/, grep s/<(.*?)>/TEXT/, $_) { print $_; } }
The script below is the timesearch script -
#!/usr/bin/perl -w use strict; my %mylist; my $min; my $max; my $range; my $line; # get the range (in this throwtogether it must be entered # with no spaces in the form HH:MM:SS.TS-HH:MM:SS.TS) # Get the range $range = <STDIN>; # Break up the range ($min, $max) = split /-/, $range; # Squeeze out leading and trailing spaces $min =~ s/^\s+//; $min =~ s/\s+$//; $max =~ s/^\s+//; $max =~ s/\s+$//; # Open the datafile and break into fields open(FILE, "mon402.log"); while (<FILE>) { if (s/<(.*?)>/TEXT/) { if ($_ =~ m/(\d+\-\w+\-\d+)\s(\d{2}\:\d{2}\:\d{2}\.\d{2})\s+(\ +w*)/) { # Push the restricted range of filenames onto a hash of ar +rays # keyed on the time field if (($2 ge $min) && ($2 le $max)) { push(@{$mylist{$2}}, $_); } } } } my @keys = sort (keys %mylist); foreach my $key (@keys) { foreach my $thing (@{%mylist}{$key}){ foreach my $it (@$thing) { print "$it\n"; last; } } }
Now they are separate scripts but I need them to be one and produce the correct results. Now the data that is being read is a datalog. The lines look like the following.
27-Jun-2001 11:34:15.77 SendSMReq:T:1074 D:19209131848 O:19209131065 +P:0x20 C:0x0 V:07-05 11:29 TEXT 27-Jun-2001 11:36:06.76 SendSMReq:T:1074 D:19207120303 O:19207131623 +P:0x20 C:0x0 V:07-05 11:35 TEXT 27-Jun-2001 11:37:51.56 SendSMReq:T:1074 D:19209138833 O:19202928969 +P:0x20 C:0x0 V:06-27 12:55 TEXT 27-Jun-2001 11:39:23.19 SendSMReq:T:1074 D:19207121543 O:Voice Mail M +WI P:0x20 C:0xe1 V:07-05 11:39 TEXT 27-Jun-2001 11:41:08.90 SendSMReq:T:1074 D:16084468213 O:16083082487 +P:0x20 C:0x0 V:06-27 12:40 TEXT
Now the timesearch script finds lines that are inbetween a timerange I specify. The grep script will grep on pretty much anything I give it. Data I would give the timesearch script is obvious but for the grep let's say I wanted to find transaction# 1074 which is (if you look in the data) right after time. Now let's say I ran the timesearch script with the grep script inside. I would get only one line back.

27-Jun-2001 11:39:23.19 SendSMReq:T:1074 D:19207121543 O:Voice Mail MWI P:0x20 C:0xe1 V:07-05 11:39 TEXT

and you can see from the data more than one for trans# 1074 exist.
So I'm trying to make the 2 work together in one script while getting the correct data output. This is giving me a big stress workout so I'd love it if somebody could help me out here.

The brassmonk
May the force be with me.

In reply to grep & timesearch by Anonymous Monk

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.