473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Log File Extracting Multi Line Records

SunOS bsm1b 5.9 Generic_118558-09 sun4u sparc SUNW,Netra-440

This is perl, v5.6.1 built for sun4-solaris

I have listed the platform/OS information for your reference.

I need to extract records from a log file with the following format:

|O%:CCLN-1-CBS1:CELLS-1-CELLS1:MCBTS-1-MC1900BTS1183
line 1
line 2
line 3
. . .
#End

There are several of these logs within the log file and I need them all. There is a distinct header and footer for each log as outlined above.

I created the following script, but it only prints one record:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.  
  3. foreach $file (@ARGV) {
  4.   open(fd1,"<$file");
  5.   $mydata = "";
  6.   while ($mydata = <fd1>) {
  7.     if ($mydata =~ /^.*MCBTS-1-MC1900BTS1183.*BTSCALLPROCESSING-1-BTSCALLPROCESSING1$/) {
  8.         print "$mydata";
  9.         $mydata = <fd1>;
  10.         until ($mydata =~ /^#END$/) {
  11.           print "$mydata";
  12.           $mydata = <fd1>;
  13.         }
  14.        print "$mydata";
  15.      }
  16.   }
  17.   close fd1;
  18. }
  19.  
Any help is appreciated.
Jan 16 '08 #1
2 1988
KevinADC
4,059 Expert 2GB
SunOS bsm1b 5.9 Generic_118558-09 sun4u sparc SUNW,Netra-440

This is perl, v5.6.1 built for sun4-solaris

I have listed the platform/OS information for your reference.

I need to extract records from a log file with the following format:

/|O%:CCLN-1-CBS1:CELLS-1-CELLS1:MCBTS-1-MC1900BTS1183
line 1
line 2
line 3
. . .
#End

There are several of these logs within the log file and I need them all. There is a distinct header and footer for each log as outlined above.

I created the following script, but it only prints one record:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.  
  3. foreach $file (@ARGV) {
  4.   open(fd1,"<$file");
  5.   $mydata = "";
  6.   while ($mydata = <fd1>) {
  7.     if ($mydata =~ /^.*MCBTS-1-MC1900BTS1183.*BTSCALLPROCESSING-1-BTSCALLPROCESSING1$/) {
  8.         print "$mydata";
  9.         $mydata = <fd1>;
  10.         until ($mydata =~ /^#END$/) {
  11.           print "$mydata";
  12.           $mydata = <fd1>;
  13.         }
  14.        print "$mydata";
  15.      }
  16.   }
  17.   close fd1;
  18. }
  19.  
Any help is appreciated.
Hard to say, the pattern you are searching:

/^.*MCBTS-1-MC1900BTS1183.*BTSCALLPROCESSING-1-BTSCALLPROCESSING1$/

look almost nothing like the sample data you posted:

|O%:CCLN-1-CBS1:CELLS-1-CELLS1:MCBTS-1-MC1900BTS1183

Do you need to use more patterns or change the one you are using? Clarify what you are looking for.
Jan 17 '08 #2
KevinADC
4,059 Expert 2GB
Heres a general Idea:

Expand|Select|Wrap|Line Numbers
  1. LOOP:  while ($mydata = <DATA>) {
  2.     if ($mydata =~ /^\Q|O%:CCLN-1-CBS1:CELLS-1-CELLS1:MCBTS-1-MC1900BTS1183\E$/) {
  3.         print "$mydata";
  4.         while ($mydata = <DATA>) {
  5.           print "$mydata";
  6.           next LOOP if $mydata =~ /#End/;
  7.         }
  8.      }
  9.   }
  10.  
  11. __DATA__
  12. |O%:CCLN-1-CBS1:CELLS-1-CELLS1:MCBTS-1-MC1900BTS1183
  13. line 1
  14. line 2
  15. line 3
  16. . . .
  17. #End
  18.  
  19. line should not print
  20. line should not print
  21. line should not print
  22. line should not print
  23.  
  24. |O%:CCLN-1-CBS1:CELLS-1-CELLS1:MCBTS-1-MC1900BTS1183
  25. line 1
  26. line 2
  27. line 3
  28. . . .
  29. #End
  30.  
  31. line should not print
  32. line should not print
  33. line should not print
Jan 17 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: googlinggoogler | last post by:
Hiya, The title says it all really, but im a newbie to python sort of. I can read in files and write files no probs. But what I want to do is read in a couple of files and output them to one...
7
by: Shane | last post by:
Hi, Thanks in advance for the help. I have been to many websites and tried several solutions to my problem, but have fixed part of it. It's time to come humbly to the newsgroups for help :-) ...
2
by: Aleander | last post by:
Hi! I have to write the records of a vector in a file, e and then open this file to extract the record to refill the vector. My program has two class: Visita(Appointment) and Data(date). The...
3
by: Mark Line | last post by:
Hello! I'm a python n00b! I've been writing in c++ for a few years so programming's not new to me, just python that I don't know the syntax!
3
by: Daniel Nogradi | last post by:
Hi list, I have an awk program that parses a text file which I would like to rewrite in python. The text file has multi-line records separated by empty lines and each single-line field has two...
9
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an...
3
by: ben.r.wood | last post by:
I am not entirely sure, but after scanning the web believe I need to use multi-dimensional arrays for my problem - although I have not seen any examples of what I am trying to achieve. I have a...
1
by: shyaminf | last post by:
hi everybody! iam facing a problem with the transfer of file using servlet programming. i have a code for uploading a file. but i'm unable to execute it using tomcat5.5 server. kindly help me how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.