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 =)
21 2623 KevinADC 4,059
Recognized Expert Specialist
What have you tried so far?
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
KevinADC 4,059
Recognized Expert Specialist
Lets see the perl code you have written so far.
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..
KevinADC 4,059
Recognized Expert Specialist
Please post your code here in this thread.
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?
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?
so what i supossed to do?
this is school work =(
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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">
|
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
|
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>
|
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.
|
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
| |
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
|
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...
|
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:
|
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
|
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 :
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |