Page 1 of 2 12>
Topic Options
#32907 - 2002-11-19 11:09 PM Need to extract info from a log file
anthonyl Offline
Fresh Scripter

Registered: 2002-11-19
Posts: 12
Loc: Work
Hi Everyone,

I am a first time poster, but long time reader of this board!!
I have been using Kix for various tasks for over a year now, but I am no expert and am struggling with what on the face of it looks a simple task.

I need to extract a list of filenames from an FTP log file.

eg
sending FTP_Iconsd.lnk 09/09/2001 20:44:00 (09/09/2001 00:00:00)
receiving IMS - Transferring Returns.doc (new file)

from the above example I need to write "FTP_Iconsd.lnk" and "IMS - Transferring Returns.doc" to a different file or a messagebox to show that those files were sent.

I can create a file that can extract each line that starts with sending or receiving, but I cant then extract the filename itself.

Any ideas as to the best way to go about this?

Thanks in advance.

Anthony.

Top
#32908 - 2002-11-19 11:12 PM Re: Need to extract info from a log file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Look up INSTR() in the KiXtart Manual
code:
$a='sending FTP_Iconsd.lnk 09/09/2001 20:44:00 (09/09/2001 00:00:00)'
$f='sending '
$b=substr($a,instr($a,$b)+len($b)+1)

will get you started.
_________________________
There are two types of vessels, submarines and targets.

Top
#32909 - 2002-11-19 11:15 PM Re: Need to extract info from a log file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I suspect you know how to read the file with readline...

so all it comes to with kix 4.00+:
code:
$line ; line from readline
$line=split($line,"receiving ")
if ubound($line)
"this file:" $line[1] ?
endif

the same with older kix:
code:
$line ; line from readline
if instr($line,"receiving ")
"this file:" substr($line,11) ?
endif

_________________________
!

download KiXnet

Top
#32910 - 2002-11-19 11:20 PM Re: Need to extract info from a log file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Using string manipulation, it should be a cinch.

1. Use InStr() to find the first space ' '
2. Use InStrRev() to find the first period '.'
3. Use the appropriate offsets from 1 and 2

As long as the the filenames all have 3 char extensions you're good to go. If not, then you will have to use slightly different logic on the sending vs. receiving lines. The lines can count backwards.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32911 - 2002-11-20 12:13 AM Re: Need to extract info from a log file
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Anthonyl,

Like Les said to make it work, analyze many many logfiles and determine the rules which the filenames follow.

eg.
each filename has a 3 char extensions or/and
only one period/line or/and
filename always after sending/receiving or/and

If you can supply use with the rules (or some more logfiles) we can give you more tips...
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#32912 - 2002-11-20 12:42 AM Re: Need to extract info from a log file
anthonyl Offline
Fresh Scripter

Registered: 2002-11-19
Posts: 12
Loc: Work
Thanks to everyone who has posted a reply so far, I am amazed at just how quick you have been!!

sending FTP_Iconsd.lnk 09/09/2001 20:44:00 (09/09/2001 00:00:00)
receiving IMS - Transferring Returns.doc (new file)

The 2 lines shown above represent the main things I am looking for. "sending " or "receiving ". The filenames can be of any length within normal LFN rules.

All I am trying to do is show a user which files have been sent or received from a logfile.

Again, thanks in advance, I am very impressed!!

Anthony. [Smile]

Top
#32913 - 2002-11-20 12:58 AM Re: Need to extract info from a log file
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
The issue is to determine some set of rules (as mentioned before) that can be used to define the start and end of the file name.

You have defined the start:
1) "sending "
2) "receiving "

Now we need to determine the what constitutes the end of the file names.

Your example lists:
1) " 20:44:00 (09/09/2001 00:00:00)" where we will use the format " 99:99:99 (99/99/9999"
2) " (new file)"

Are these the only two formats of text that follow the file name?

If so I can provide you a solution.

[ 20. November 2002, 00:59: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#32914 - 2002-11-20 01:00 AM Re: Need to extract info from a log file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
as you still did not say what version of kix you have...
eh, have to come along with this then.
code:
$line ; the line you read from somewhere.
if substr($line,1,8)="sending "
$line=substr($line,9)
$line=substr($line,1,instr($line,".")+3)
"Sent file:" $line
endif
if substr($line,1,10)="receiving "
$line=substr($line,11)
$line=substr($line,1,instr($line,".")+3)
"Received file:" $line
endif

_________________________
!

download KiXnet

Top
#32915 - 2002-11-20 01:04 AM Re: Need to extract info from a log file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jooel,
It is possible to have more than one dot '.' in a filename so that is why I proposed a reverse search. It may look like the number of chars after the filename may always be the same so may be able to just count backwards from Len().
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32916 - 2002-11-20 01:09 AM Re: Need to extract info from a log file
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Jooel,

Like Les said (he beat me... damn that checker [Wink] ) what about a file named: we.love.kixtart.org

Anyways the questions to Anthony are:
Is there a period in the line after the filename extension?
Do all files have an extenstion?
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#32917 - 2002-11-20 01:12 AM Re: Need to extract info from a log file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Since the date and time are padded out with leading zeros, I'm betting the tails are all a fixed length so just need to count backwards.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32918 - 2002-11-20 01:14 AM Re: Need to extract info from a log file
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
This is a regular expression issue.

For those interested in a KiXtart RegEx example: KiXtart Golf Solution(s)

[ 20. November 2002, 01:20: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#32919 - 2002-11-20 01:18 AM Re: Need to extract info from a log file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Yeah, I know. Jooel came up with a cheap&dirty script that would choke on extra dots. Anthony doesn't answer our questions.

I for one, am not going to assume facts not in evidence and put to code those assumptions.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32920 - 2002-11-20 01:28 AM Re: Need to extract info from a log file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
les, dunno, I just want to raise our postcounts!

I know that my script has nothing to do with reality, but that I could do with what he gave.
_________________________
!

download KiXnet

Top
#32921 - 2002-11-20 07:06 PM Re: Need to extract info from a log file
anthonyl Offline
Fresh Scripter

Registered: 2002-11-19
Posts: 12
Loc: Work
Hi Howard,

In reply to your previous message, you are correct in saying that the rules to follow are only as described below.

"The issue is to determine some set of rules (as mentioned before) that can be used to define the start and end of the file name.

You have defined the start:
1) "sending "
2) "receiving "

Now we need to determine the what constitutes the end of the file names.

Your example lists:
1) " 20:44:00 (09/09/2001 00:00:00)" where we will use the format " 99:99:99 (99/99/9999"
2) " (new file)"

Are these the only two formats of text that follow the file name?

If so I can provide you a solution."

Top
#32922 - 2002-11-20 07:50 PM Re: Need to extract info from a log file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Ok, so anthony answered the question with a question...

I can work with that. On further thought, decided on doing it all from left to right instead of both ends to the middle.
code:
Break on
$sending='sending FTP_Iconsd.lnk 09/09/2001 20:44:00 (09/09/2001 00:00:00)'

if instr($sending,'sending ')
$b=substr($sending,instr($sending,' ')+1,(instr($sending,'/')-instr($sending,' '))-4)
endif
'['+$b+']' ?

$receiving='receiving IMS - Transferring Returns.doc (new file)'
if instr($receiving,'receiving ')
$c=substr($receiving,instr($receiving,' ')+1,(instr($receiving,'(')-instr($receiving,' '))-2)
endif
'['+$c+']' ?
get $_

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32923 - 2002-11-20 07:54 PM Re: Need to extract info from a log file
anthonyl Offline
Fresh Scripter

Registered: 2002-11-19
Posts: 12
Loc: Work
Thanks to everyone who contributed I really appreiciate it.

With some help from Lonkero's code earlier, I have managed to get it working with :-

; $line is taken from a readline()
if substr($line,1,8)="sending "
$line=substr($line,9)
$dot=instr($line,".")
$line=substr($line,1,$dot + 3)
? "Sent file: " $line
endif

Works a treat, thanks again [Smile] [Smile] [Smile]

Anthony.

Top
#32924 - 2002-11-20 07:54 PM Re: Need to extract info from a log file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
OK, before I get flamed... will point out some flaws.

If the words 'sending' or 'receiving' naturally occur elsewhere within the string, it's a bomber. Don't you just hate Murphy-proofing...

This is not bullet-proof code, just a point of discussion.

The glove is down for any that rises to the challenge.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32925 - 2002-11-20 07:56 PM Re: Need to extract info from a log file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
les, your code is not full and now I can give you a [Razz]

mostlikely:
$sending=$receiving
_________________________
!

download KiXnet

Top
#32926 - 2002-11-20 08:00 PM Re: Need to extract info from a log file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well, that's what I deserve for using Jens' code as a starting point. [Roll Eyes]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 484 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.069 seconds in which 0.022 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org