Well I figured it out now with your guys help. It's complete. Well the script isn't but the know-how of it is. I read about $/ and $. and $* in a book but I didn't know how to make them work and I knew that is what I needed. I was lacking the split line with @lines that was my downfall. I didn't know how to tell PERL what the newline was but I see from your entries how to do it. The damn book didn't tell me I needed to do that.
Anyway I'll post the script below. It's really rough as of right now because I haven't touched it up that much. It doesn't have warnings on or anything at all but I'll fix that. I was just testing. The tests all came back true. Everything is cool. Here is the script.
#!/usr/bin/perl
chomp($msisdn = <STDIN>);
$/ = ""; # read paragraphs
$cell = "Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'
+4F07";
while ($para = <>) {
$lastHeading;
@lines = split(/\n/, $para);
if (@lines == 1) # A Heading
{
$lastHeading = $lines[0];
next;
}
if ($lastHeading eq "MSTerminating") {
if ($lines[8] =~ m/$msisdn/) {
if ($lines[5] =~ m/$cell/) {
print "$lastHeading\n";
print "\n";
print "Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'MA
+D023A\n";
print "$lines[8]\n"; # ninth line
print "$lines[4]\n"; # fifth line
}
}
elsif ($lastHeading eq "MSORIGINATING") {
if ($lines[7] =~ m/$msisdn/) {
print $lines[7]; # eigth line
}
}
elsif ($lastHeading eq "mSOriginatingSMSinSMSIWMSC") {
if ($lines[4] =~ m/$msisdn/) {
print "$lines[4]\n"; # fifth line
}
}
}
}
Well as you can see I got the script to only print off the lines I wanted when it finds the phone number or $msisdn and the $cell line. Well I have a lot more lines to add that aren't in there but the MSTerminating block should give you the best idea of what I was trying to accomplish and finally did. It works seamlessly right now. PERL can do anything! Here's the reason I wanted to rewrite this into PERL. One for easy maintenance and updates and 2 to rewrite something a former employee wrote that in my opinion being a disliker of AWK is a hideous script.
Here it is.
# Asks input for what msisdn (phone number) you are looking for and th
+en it appends it's output to a file otherwise it is displayed on scre
+en.
# The fields, Called, Calling, and Redirecting are fields pulled out o
+f the TTFILES
# Script modified by David M. Hagens
# Original script creator Jeff Toles
# Copyright Airadigm Communications
#!/usr/bin/sh
echo "What msisdn?"
read msisdn
awk "BEGIN{ msisdn=\"$msisdn\"; }"'
{ #printf("%s\n", ARGV[2])
line14 =line13
line13 =line12
line12 =line11
line11 =line10
line10 =line9
line9 =line8
line8 =line7
line7 =line6
line6 =line5
line5 =line4
line4 =line3
line3 =line2
line2 =line1
line1 =$0 } /Called/ {if(match($9,msisdn)) a=1;}
a>0 {if(a==1&&match(line12,"MSTerm")) {print "\n" line12"\n" line2"\n"
+line1;MSTerm=1}
if(a==1&&match(line11,"TRANSIT")) {print "\n" line11"\n" line2"\n"line
+1; Transit=1}
if((a==8||a==9||a==10)&&MSTerm) print $0
if((a==6||a==7||a==8)&&Transit) print $0
if (a++>10) { a=0;MSTerm=0;Transit=0};
}
/Calling/ {if(match($9,msisdn)) b=1;}
b>0 {if(b==1&&match(line10,"MSORIG")) {print "\n" line10"\n"; MSOrig=
+1}
if(b==1&&match(line10,"TRANSIT")){print "\n" line10"\n"; Transit=1}
if((b<=2||b==5||b==7||b==8)&&MSOrig) print $0
if((b<=2||b==7||b==8||b==9)&&Transit) print $0
if (b++>8) { b=0; MSOrig=0;Transit=0};
}
/Redirecting/ {if(match($8,msisdn)) c=1;}
c>0 {if(c==1&&match(line14,"CallForward")) print "\n" line14"\n" line5
+"\n" line4"\n" ;
if(b<=5) print $0
if (c++>5) { c=0;};
}' output.abbazabba > msisdnoutput.abbazabba; echo "The file with your
+ search results is called "msisdnoutput.abbazabba""
I rewrote some of it such as to get it to read STANDARD IN before you had to manually enter the msisdn number by editing the script and inserting the number you wanted in a msisdn variable. Then the output is sent to a file. Otherwise all the AWK syntax is from a former employee. I know what the scripts accomplishing but I'll be damned if I can read AWK or alter this script to get it to do what I want so as much as I hate reinventing the wheel it was for the best. I'll give him this he is good with AWK because that's the only language he uses. I still think it sucked.
The only downside of this script is I got a list of cell sites (The thing mentioned in $cell = "Blah") and they are to the BASE 10 and they are a separate list that gives the city code of the cell site which is in BASE 16.
For example: MAD023A 310-64-1101-20231 <--This is the BASE 10 form and is represting our 23rd cell site sector in Madison Wisconsin, It's one of the cell sites a big list of them.
Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'4F07 <--This example is the same exact thing to the BASE 16 which is in the text that I go through.
So in the end I want it to print --> Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'MAD023A' as in the script.
Now I read in the 3rd Edition Perl Programming that their is a base class/object but it's definition is devoid of any relation to number bases just as HEX isn't mentioned.
I'm wondering is their an easy way to just tell PERL the following:
If you match x'4F07' on $lines5 of "MSTerminating" :(
Extreme not smily face because I just realized this is going to have to be a manual process either way I do it.
Reason I say that is Bcuz my boss wants it printed out as I have it in the script otherwise I'd just print the appropriate line from the file that contains the city name and BASE 10 code.
Thanks so much. This is the best PERL FORUM on Earth and on the net.
Thanks bikeNomad & thanks DA or Dan
You guyz are cool.
I'll check up on this see if you guys throw in any pointers. THANKS!
The Brassmon_k
David M. Hagens
|