473,626 Members | 3,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Log File Extracting Multi Line Records

1 New Member
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 1998
KevinADC
4,059 Recognized Expert Specialist
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.* BTSCALLPROCESSI NG-1-BTSCALLPROCESSI NG1$/

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 Recognized Expert Specialist
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
3052
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 single file, but then be able to take this one single file and recreate the files I put into it. Im really at a loss as to how I go about recovering the files?
7
1895
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 :-) By the way, please don't reply just to tell me that my code isn't optimized and that I should use a delimited database rather than a line by line record. If I had my way, I'd do it differently too.
2
1868
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 second one is used in the first one such as a field. I wrote the scrivi() function to write the record in a file called "archivio.txt" and it works fine. The I wrote the carica() function to load the records that I have placed on the file, but I...
3
2401
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
6260
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 subfields: node 10 x -1 y 1
9
1977
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 ArrayList? I have tried looping through the logfile using regex, if statements and flags to find the start and end of each message but I do not see a good time in this process to create a new instance of my Message object. While messing around with...
3
2114
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 form with one field, for which a user will submit a lump of delimited data. The data will always be in the same format, ie. 5 fields per record, each field has a delimeter and a new row starts a new record. for example:
1
5585
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 execute it using tomcat server5.5. the code is as follows. if you have any other coding regarding this, please send me.it's urgent. import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*;
0
8705
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8638
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8505
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5574
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2626
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.