473,748 Members | 2,847 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
21 2622
KevinADC
4,059 Recognized Expert Specialist
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.
Jun 19 '07 #11
drushof
12 New Member
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?
Jun 19 '07 #12
KevinADC
4,059 Recognized Expert Specialist
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\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

so you would skip them (move on to the next line) until you find a line that does interest you.
Jun 19 '07 #13
drushof
12 New Member
im sorry..but im new in perl..
any advise for my code?
thx
Jun 19 '07 #14
KevinADC
4,059 Recognized Expert Specialist
any advise for my code?
Yes, use regular expressions to parse the data to get the results you want.
Jun 20 '07 #15
drushof
12 New Member
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?
Jun 20 '07 #16
KevinADC
4,059 Recognized Expert Specialist
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.
Jun 20 '07 #17
drushof
12 New Member
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?
Jun 20 '07 #18
KevinADC
4,059 Recognized Expert Specialist
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:

Expand|Select|Wrap|Line Numbers
  1. $line = 'Recovering 5 files within D:\X\Y\ into E:\restore';
  2. if ($line =~ /^Recovering \d+ files within (\S+) into (\S+)/ ) {
  3.    print "$1 $2";
  4. }
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
Jun 20 '07 #19
drushof
12 New Member
thx so much..
im gonna try it =)
Jun 20 '07 #20

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

Similar topics

3
3659
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
3957
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
3504
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
2462
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
4864
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
4385
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
1990
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
4511
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
2833
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
3613
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
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
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,...
0
9548
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
9325
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
8244
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...
0
6076
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
4607
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...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
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.