OK that worked for the lines printing. Thank you, I understand it. I just didn't know that PERL would know what lines to print if you split on the newline. I'm very unfamiliar with multi-line as I said. I'm having problems with one last thing though. I'll show you a small portion of the text I'm working with and what I want to do is limit what the script prints. I'm sorry you guys told me exactly what I wanted to know but I started off with a simple explanation, well as easy as I could so I could work on the last part later. I'll show you the text I'm going through then I'll show you how I modified Bike Nomads script with your idea and made it work.
mSOriginatingSMSinSMSIWMSC Call Identification Number: 10275084 Record Sequence Number: 2205369 Exchange Identity: MAPP01E 0117802 MSC Identification: TON: 1 NPI: 1 MSISDN: 19207079800 Calling Party Number: TON: 1 NPI: 1 MSISDN: 19207029659 Date for Start of Charge: 01/07/18 Time for Start of Charge: 00:14:33 Traffic Activity Code: TeleService Code: x'22 Service Centre Address: TON: 1 NPI: 1 MSISDN: 14147139800 Charged Party: 0 Miscellaneous Information: NULL MSTerminating Call Identification Number: 10275019 Related Call Number: 10275004 Record Sequence Number: 2205370 Exchange Identity: MAPP01E 0117802 MSC Identification: TON: 1 NPI: 1 MSISDN: 19207079800 Cell ID for First Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'4F07 Incoming Route: MAD01TI Outgoing Route: BAPL01O Calling Party Number: TON: 4 NPI: 1 MSISDN: 6082572086 Called Party Number: TON: 1 NPI: 1 MSISDN: 16084466501 IMSI: 310640010049547 IMEI: NULL Mobile Station Roaming Number: TON: 1 NPI: 1 MSISDN: 16084469974 Redirecting Number: NULL Redirection Counter: 0 Original Called Number: NULL Date for Start of Charge: 01/07/18 Time for Start of Charge: 00:14:33 Chargeable Duration: 00:00:00 Traffic Activity Code: *020 TeleService Code: x'11 Bearer Service Code: NULL Internal Cause and Loc: LOCATION: 2 CAUSE: 61 Time from Register Seizure to Start of Charging: 00:00:18 Time for Stop of Charging: 00:14:33 Interruption Time: 00:00:00 Type of Calling Subscriber: 1 Disconnecting Party: 2 Charged Party: 1 Fault Code: NULL eosInfo: x'0 Call Position: 2 Miscellaneous Information: NULL Restart During Call: NULL Restart Between Disc and Output: NULL Origin for Charging: x'1 Cell ID for Last Cell: MCC: 310 MNC: 64 LAC: x'44D CI: x'4F1D Location Number: TON: 1 NPI: 1 MSISDN: 14147089800 Output for Subscriber: NULL Last Partial Output: NULL Partial Output Rec Num: NULL Regional Service Used: NULL Region Dependent Charging Origin: NULL Transparency Indicator: NULL dTMFUsed: NULL Tariff Class: x'A Tariff Switch Indicator: 0 SS Code: NULL ICI Ordered: NULL
Now for the script
#!/usr/bin/perl chomp($msisdn = <STDIN>); $/ = ""; # read paragraphs while ($para = <>) { $lastHeading; @lines = split(/\n/, $para); if (@lines == 1) # A Heading { $lastHeading = $lines[0]; next; } my $hitMe; if ($msisdn && $lastHeading eq "MSTerminating") { #if ($lastHeading eq "MSTerminating") { print $lines[13]; # twelth line print $lines[2]; # third line print $lines[5]; # sixth line print $lines[4]; # fifth line } elsif ($lastHeading eq "MSORIGINATING") { $hitMe = $lines[5]; # sixth line } elsif ($lastHeading eq "mSOriginatingSMSinSMSIWMSC") { print $lines[5]; } }
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

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.