Page 2 of 2 <12
Topic Options
#32927 - 2002-11-20 08:01 PM Re: Need to extract info from a log file
anthonyl Offline
Fresh Scripter

Registered: 2002-11-19
Posts: 12
Loc: Work
Les,

I take your point but in my specific case, the words "sending " and "receiving " do not occur anywhere else and wont either.

Ant

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

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
{edit} Was critiqueing my code, not your's.

Yeah, but what about the dot as in Lurenko's version.

Excuse that brain fart of earlier. Here's some better code.
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,9,(instr($sending,'/')-12))
endif
'['+$b+']' ?

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



[ 20. November 2002, 20:10: Message edited by: LLigetfa ]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32929 - 2002-11-20 10:23 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 script has still the same error.
you have already set the lines separated and that is not RL issue.
or how the initial split from 20M logfile should be parsed to two lines which are somehow passed to 2 vars and even named sending and receiving before even checking the data (as you have them before the if's [Wink] )?
_________________________
!

download KiXnet

Top
#32930 - 2002-11-20 10: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
Jooel,
Now I know you're just yanking my chain... [Wink]

It is after all, just a proof of concept. $sending and $receiving would be replaced by a $Line var in a ReadLine() loop.

But then again, you already know that but are crying 'sour grapes' because my code is better than yours. [Big Grin]

Try your code with:
sending we.love.kixtart.org.lnk 09/09/2001 20:44:00 (09/09/2001 00:00:00)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#32931 - 2002-11-21 12:37 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
anthonyl, how can you state that a file name would never ever contain "sending" or "receiving" as part of the file name. It may be unlikely, but a good coder will make every attempt to avoid the problem if at all possible.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#32932 - 2002-11-21 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
Howard,
Repeating yourself in your old age... [Razz]

You are correct however that a programmer would try to exclude all potential pitfalls. Guess that's why I'm not a programmer. Always hated the Murphy-proofing.

So my last revision of code is still like swiss cheese. The IF statements under the conditions previously mentioned could return a false positive. I only say could because without knowing what all is in the source text file one can only surmise.

so:
if instr($sending,'sending ')

whould be more accurate as:
if left($sending,8)='sending '

Ditto for:
if instr($receiving,'receiving ')

should be:
if left($receiving,10)='receiving '

As for 'optimistic' code, Ruud had this to say in an interview

quote:
Steve:
Do you have any tips that will help admins write more efficient code?
Ruud:
Mmm, let me think on that for a second.

Adding proper error handling to scripts.

(Most scripts I get to see are, Mmm, very 'optimistic' about the actions in them).

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

Top
#32933 - 2002-11-21 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
I removed my duplicate post [Embarrassed]

...so that I could explain the obvious and increase my post count [Wink]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 2 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.054 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

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