473,699 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing a Log File

12 New Member
hello im new with perl
i must do parse log file from networker

with format look like this :

Start time: 2-16-07 11:27a
Recovering files of client 'blablabla' from server 'bliblibli'.
Recover: Total estimated disk space needed for recover is 3 MB.
Recovering 5 files within D:\X\Y\ into E:\restore
Requesting 5 file(s), this may take a while...
E:\restore\blab la\blablabla.bl a
E:\restore\blab la\blablabla.bl i
E:\restore\blab la\blablabla.bl u
E:\restore\blab la\blablabla.bl e
E:\restore\blab la\blablabla.bl o
Received 5 file(s) from NSR server 'blablabla'
Recover completion time: Fri Feb 16 11:30:52 2007

and the data,i need:
start time,completion time,client name,server name,total file,and disk space

i have problem with regex,grep,spli t..is anyone can help me?
thx before =)
Jun 18 '07 #1
21 2620
KevinADC
4,059 Recognized Expert Specialist
What have you tried so far?
Jun 18 '07 #2
drushof
12 New Member
What have you tried so far?
Start time: 2-16-07 11:27a
Recovering files of client 'blablabla' from server 'bliblibli'.
Recover: Total estimated disk space needed for recover is 3 MB.
Recovering 5 files within D:\X\Y\ into E:\restore
----> this is oke..


and then how can i go to the last line to get the completion date,
because every file has different amount of files to recover.(in this example 5 files)
i dont have idea to make the loop
Jun 18 '07 #3
KevinADC
4,059 Recognized Expert Specialist
Lets see the perl code you have written so far.
Jun 18 '07 #4
drushof
12 New Member
Lets see the perl code you have written so far.
o yea i forgot to tell that i just make the prosedur for each line, not a whole file..
Jun 18 '07 #5
KevinADC
4,059 Recognized Expert Specialist
Please post your code here in this thread.
Jun 18 '07 #6
drushof
12 New Member
i've done this :

use strict;
use warnings;

open (LOGFILE, "Restoremarble. log") || die "couldn't open the file!";
my @line = <LOGFILE>;

#line 1
my $list = $line[0];
my @list_t = split(/ /,$list);

my @grepNames = grep(/^\d/, @list_t);
my $el1 = $grepNames[0];
my $el2 = $grepNames[1];

my @list_date = split('-',$el1);
my @list_time = split(':',$el2) ;

print "-----------------\n";
print "day :$list_date[0]\n";
print "month :$list_date[1]\n";
print "year : $list_date[2]\n";
print "time : $list_time[0]-$list_time[1]\n";

#line 2
my $list2 = $line[1];
my @list_t2 = split(/ /,$list2);

my @grepNames2 = grep(//,@list_t2);
my $el1a = $grepNames2[4]; #client
my $el2a = $grepNames2[7]; #server


print "-----------------\n";
print "client : $el1a\n";
print "server : $el2a\n";

#line 3
my $list3 = $line[2];
my @list_t3 = split(/ /,$list3);

my @grepNames3 = grep(/^\d/,@list_t3);
print "--------------\n";
print "Total disk : $grepNames3[0]\n";

#2 last line
my $list4 = $line[-2];
my @list_t4 = split(/ /,$list4);

my @grepNames4 = grep(/^\d/,@list_t4);
print "-----------------\n";
print "Total files : $grepNames4[0]\n";

#last line
my $list5 = $line[-1];
my @list_t5 = split(/ /,$list5);

print "---------------------\n";
print "day : $list_t5[5]\n"; #day
print "month : $list_t5[4]\n"; #month
print "year : $list_t5[7]"; #year
print "time : $list_t5[6]\n"; #time

close(LOGFILE);
exit 0;

is it correct?
Jun 19 '07 #7
KevinADC
4,059 Recognized Expert Specialist
It's not the way I would do it and the results look incomplete based on the data you posted. When I run your script with the sample data this is the output:

-----------------
day :2
month :16
year : 07
time : 11-27a

-----------------
client : 'blablabla'
server : 'bliblibli'.

--------------
Total disk : 3
-----------------
Total files :
---------------------
day :
month :
year : time :

so while your code could be improved and does not return all the data you wanted, completion time and total file are missing, at least it runs. It uses "strict" and "warnings" (very good), and does produce most of the output you want. Is this school work or some sort of learning excersize?
Jun 19 '07 #8
drushof
12 New Member
so what i supossed to do?
this is school work =(
Jun 19 '07 #9
drushof
12 New Member
i've improved it :

use strict;
use warnings;

open (LOGFILE, "bla.log") || die "couldn't open the file!";
my @line = <LOGFILE>;

#line 1
my $list = $line[0];
my @list_t = split(/ /,$list);

my @grepNames = grep(/^\d/, @list_t);
my $el1 = $grepNames[0];
my $el2 = $grepNames[1];

my @list_date = split('-',$el1);
my @list_time = split(':',$el2) ;

print "-----------------\n";
print "day :$list_date[1]\n";
print "month :$list_date[0]\n";
print "year : $list_date[2]\n";
print "time : $list_time[0]-$list_time[1]\n";

#line 2
my $list2 = $line[1];
my @list_t2 = split(/ /,$list2);

my @grepNames2 = grep(//,@list_t2);
my $el1a = $grepNames2[4]; #client
my $el2a = $grepNames2[7]; #server


print "-----------------\n";
print "client : $el1a\n";
print "server : $el2a\n";

#line 3
my $list3 = $line[2];
my @list_t3 = split(/ /,$list3);

print "-------------------\n";
print "Total size : $list_t3[9] $list_t3[10]\n";

# my @grepNames3 = grep(/^\d/,@list_t3);
# print "--------------\n";
# print "Total disk : $grepNames3[1]\n";

#2 last line
my $list4 = $line[-2];
my @list_t4 = split(/ /,$list4);

my @grepNames4 = grep(/^\d/,@list_t4);
print "-----------------\n";
print "Total files : $grepNames4[0]\n";

#last line
my $list5 = $line[-1];
my @list_t5 = split(/ /,$list5);

print "---------------------\n";
print "day : $list_t5[5]\n"; #day
print "month : $list_t5[4]\n"; #month
print "year : $list_t5[7]"; #year
print "time : $list_t5[6]\n"; #time

close(LOGFILE);
exit 0;

content of bla.log is same with the first post
Jun 19 '07 #10

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

Similar topics

3
3657
by: Willem Ligtenberg | last post by:
I decided to use SAX to parse my xml file. But the parser crashes on: File "/usr/lib/python2.3/site-packages/_xmlplus/sax/handler.py", line 38, in fatalError raise exception xml.sax._exceptions.SAXParseException: NCBI_Entrezgene.dtd:8:0: error in processing external entity reference This is caused by: <!DOCTYPE Entrezgene-Set PUBLIC "-//NCBI//NCBI Entrezgene/EN" "NCBI_Entrezgene.dtd">
2
3953
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home Canonicalpath-Directory4: \\wkdis3\ROOT\home\bwe\ You selected the file named AAA.XML getXmlAlgorithmDocument(): IOException Not logged in
3
3501
by: Pir8 | last post by:
I have a complex xml file, which contains stories within a magazine. The structure of the xml file is as follows: <?xml version="1.0" encoding="ISO-8859-1" ?> <magazine> <story> <story_id>112233</story_id> <pub_name>Puleen's Publication</pub_name> <pub_code>PP</pub_code> <edition_date>20031201</edition_date>
1
2459
by: Christoph Bisping | last post by:
Hello! Maybe someone is able to give me a little hint on this: I've written a vb.net app which is mainly an interpreter for specialized CAD/CAM files. These files mainly contain simple movement and drawing instructions like "move to's" and "change color's" optionally followed by one or more numeric (int or float) arguments. My problem is that the parsing algorithm I've currently implemented is extremely slow.
4
4859
by: Rick Walsh | last post by:
I have an HTML table in the following format: <table> <tr><td>Header 1</td><td>Header 2</td></tr> <tr><td>1</td><td>2</td></tr> <tr><td>3</td><td>4</td></tr> <tr><td>5</td><td>6</td></tr> </table> With an XSLT styles sheet, I can use for-each to grab the values in
3
4379
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in the file) with the location. And for a particular section I parse only that section. The file is something like, .... DATAS
9
1985
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...
13
4508
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple command set consisting of several single letter commands which take no arguments. A few additional single letter commands take arguments:
13
2828
by: charliefortune | last post by:
I am fetching some product feeds with PHP like this $merch = substr($key,1); $feed = file_get_contents($_POST); $fp = fopen("./feeds/feed".$merch.".txt","w+"); fwrite ($fp,$feed); fclose ($fp); and then parsing them with PHP's native parsing functions. This is succesful for most of the feeds, but a couple of them claim to be
2
3608
by: Felipe De Bene | last post by:
I'm having problems parsing an HTML file with the following syntax : <TABLE cellspacing=0 cellpadding=0 ALIGN=CENTER BORDER=1 width='100%'> <TH BGCOLOR='#c0c0c0' Width='3%'>User ID</TH> <TH Width='10%' BGCOLOR='#c0c0c0'>Name</TH><TH width='7%' BGCOLOR='#c0c0c0'>Date</TH> and so on.... whenever I feed the parser with such file I get the error :
0
9181
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...
1
8924
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8889
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...
0
7756
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6537
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
5877
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
4378
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
3060
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
2
2353
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.