On 11-10-10 03:56 PM, Chris Stinemetz wrote:
Any help is appreciated.
Once I match HEH how can alter the program to print the contents that
are in the two lines directly above the match?
For example in this case I would like the print results to be:
**01 REPT:CELL 983 CDM 1, CCU 1, CE 5, HEH Timestamp: 10/10/11 00:01:18
This is not quite what you asked for but it shows how to print lines
before a match:
#!/usr/bin/env perl
use strict;
use warnings;
# number of lines to save
my $save_nbr = 2;
# save lines before pattern match
# use undef for lines before beginning
my @lines = ( undef ) x $save_nbr;
while(my $hehline = <DATA>) {
chomp $hehline;
if ($hehline =~ /, HEH/) {
# print before lines
print "$_\n" for ( grep { defined } @lines );
# print current line
print "$hehline\n";
}
# remove first saved line
shift @lines;
# save current line
push @lines, $hehline;
}
__DATA__
10/10/11 00:01:17 #984611
A 01 REPT:CELL 833 CP FAILURE, UNANSWERED TERMINATION
CDMA TRAFFIC CHANNEL CONFIRMATION FAILURE
TRAFFIC CHANNEL FAILURE REASON - ACQUIRE MOBILE FAILURE [2]
DCS 1 TG 1723 TM 374 SG 0 ANT 2
CARRIER 4, CHAN UNAVAIL FS-ECP ID 1, SYS ID 4681
DN 3168710330, MIN 3164094259, IMSI UNAVAIL
SN ###2ddff3 MEID Xa00000###629cc SCM ba
ALW CDMA, ASGN CDMA
CDM 1, CCU 2, CE 64, MLG 1/MLG_CDM 1
DCS 1/PSU 0/SM 3/BHS 6, ECP ID 1, SYS ID 4681
10/10/11 00:01:18 #984614
**01 REPT:CELL 983 CDM 1, CCU 1, CE 5, HEH
SUPPRESSED MSGS: 0
FT PL SECTOR 3 CARRIER 1 (1.9 GHz PCS)
FAILURE: OUT OF RANGE
PILOT LEVEL: MEASURED = 28.3 dBm EXPECTED = 33.8 dBm
SECONDARY UNIT: CDM 1, CBR 3
--
Just my 0.00000002 million dollars worth,
Shawn
Confusion is the first step of understanding.
Programming is as much about organization and communication
as it is about coding.
The secret to great software: Fail early & often.
Eliminate software piracy: use only FLOSS.
"Make something worthwhile." -- Dear Hunter
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/