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.#!/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 } } } }
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.# 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""
In reply to Re: Re: Re: Re: Can PERL know a line without matching?
by brassmon_k
in thread Can PERL know a line without matching?
by brassmon_k
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |