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.
The script below is the timesearch 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 $_; } }
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.#!/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 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: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
In reply to grep & timesearch by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |