in reply to Can PERL know a line without matching?
Are you:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Can PERL know a line without matching?
by Anonymous Monk on Jul 28, 2001 at 00:39 UTC | |
The Brassmon_k The examples above helped me a little but am still not getting correct results. I can't seem to get the script to print off any other even if it matches them except for the line with the phone number in it. | [reply] |
by da (Friar) on Jul 28, 2001 at 03:02 UTC | |
You have a text file with records which start with a newline, a line of text, and another newline. You want to print selected lines from a record, if both the following are true: the record title matches a predefined list, and the phone number is in the record. The title of the record determines which lines of the record to print. Your question for us is how to find out what record you're looking at. It sounds like bikenomad's code should do almost exactly that, if you simply include print statements inside the if statement: Does this help?
| [reply] [d/l] [select] |
by brassmon_k (Sexton) on Jul 31, 2001 at 01:57 UTC | |
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. 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 | [reply] [d/l] [select] |
by brassmon_k (Sexton) on Jul 30, 2001 at 20:39 UTC | |
Now for the script As you can see from the script what I'm trying to do is have the Title of the record block and the lines I specifiy per block to print only if the script finds the $msisdn in any of the blocks. That's the phone number or 10th line #11th if you count Title "MSTerminating" as line 1 for a block. At the end the number is 6082572086. So for example since that is the number I'm interested in, the only record block which contains the number I'm searching for is "MSTerminating" and not any of the other record blocks so I'd want it to print off only the lines for "MSTerminating" as that is the only place the number was found. I was thinking of doing "if (grep, $msisdn) {" then your if The && operator I used didn't seem to work. The && operator confuses me as to me the logic says if this and that do what I tell you to. It hates me though. I was thinking of doing a couple variations but you guys have helped me with the hardest part in my opinion because I didn't know multi-line. I'll remember what you guys taught me so I'm not back here nagging you guys all the time. I can write regex's to search inside files for single lines and search files in directories and "printem"(Possible new print statement? LOL) or pull them but this was something different and I read the books but half the stuff was reading greek to me cuz I never had to use it. Some of the stuff I think you just gotta use it to understand it. Well please offer your advice on the last portion. Thankyou lots, Dave | [reply] [d/l] [select] |
by da (Friar) on Jul 30, 2001 at 23:57 UTC | |
by scain (Curate) on Jul 28, 2001 at 00:56 UTC | |
You need to keep every line in the block, probably by assigning each line as an element of an array. After you determine that a text block is the one you want, you can print each line you want from the array, or all of them. How you decide to print a given line could be done with a regex or grep or other possiblities. If you can't get it to work now, post some code, and we'll give you pointers. Scott | [reply] |