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\blabla\blablabla.bla
E:\restore\blabla\blablabla.bli
E:\restore\blabla\blablabla.blu
E:\restore\blabla\blablabla.ble
E:\restore\blabla\blablabla.blo
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,split..is anyone can help me?
thx before =)
21 2587
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
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..
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?
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
You need a way to skip the lines that don't interest you and find the ones that do. You can use a regexp to do that. Since this is school work I leave that up to you to figure out.
You need a way to skip the lines that don't interest you and find the ones that do. You can use a regexp to do that. Since this is school work I leave that up to you to figure out.
skip the line??
sorry i dont get it
yea im gonna figure it out..do i have the right step?
Your entire approach is really quite awkward but I have no idea how far along you are in your perl studies. If you have already covered regular expressions you should be using them to find the lines you want to parse data out of. But maybe the assignment dictates what functions you have to use to get the output.
As far as skipping goes, these lines do not seem to interest you:
E:\restore\blabla\blablabla.bla
E:\restore\blabla\blablabla.bli
E:\restore\blabla\blablabla.blu
E:\restore\blabla\blablabla.ble
E:\restore\blabla\blablabla.blo
so you would skip them (move on to the next line) until you find a line that does interest you.
im sorry..but im new in perl..
any advise for my code?
thx
any advise for my code?
Yes, use regular expressions to parse the data to get the results you want.
use regular expressions to parse the data to get the results you want.
mmh oke..but is my code wrong?
or regular expression make it easier?
mmh oke..but is my code wrong?
or regular expression make it easier?
There is no way for me to know if your code is wrong. That depends on how much perl you have learned already and how much you are expected to know at this point in your studies.
Technically, if the code runs and poduces the correct results, it's good code. It may not be efficient code, but it's good. Your code is close to producing the results you want.
Using regular expressions should make the job easier.
thx so much
another question,can you help me
Recovering 10 files within C:\ABC\DEF\ into F:\XYZ\PQR\
data i need C:\ABC\DEF\ and F:\XYZ\PQR\
how regular expression solve this thing?
OK you beat some code out of me, but since this is your school work don't expect anymore code. This is one possible way to match the pattern you are interested in: - $line = 'Recovering 5 files within D:\X\Y\ into E:\restore';
-
if ($line =~ /^Recovering \d+ files within (\S+) into (\S+)/ ) {
-
print "$1 $2";
-
}
here are a couple of regexp tutorials:
# perlrequick - Perl regular expressions quick start
# perlretut - Perl regular expressions tutorial
you can find them here: http://perldoc.perl.org/index-tutorials.html
thx so much..
im gonna try it =)
- $line = 'Recovering 5 files within D:\X\Y\ into E:\restore';
-
if ($line =~ /^Recovering \d+ files within (\S+) into (\S+)/ ) {
-
print "$1 $2";
-
}
sorry but in other case like 'Recovering 10 files within D:\X Y's\Z into E:\restore'
the code didnt work
what should i supposed to do to avoid the space and '
thx
You're going to have to read the tutorials I linked you to (or read whatever perl resource material you have). You will find the answers to your questions in those tutorials.
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...
|
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...
|
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>...
|
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...
|
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>...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
| |