#32907 - 2002-11-19 11:09 PM
Need to extract info from a log file
|
anthonyl
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
|
|
|
|
#32912 - 2002-11-20 12:42 AM
Re: Need to extract info from a log file
|
anthonyl
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.
|
|
Top
|
|
|
|
#32913 - 2002-11-20 12:58 AM
Re: Need to extract info from a log file
|
Howard Bullock
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 ]
|
|
Top
|
|
|
|
#32914 - 2002-11-20 01:00 AM
Re: Need to extract info from a log file
|
Lonkero
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
|
|
|
|
#32918 - 2002-11-20 01:14 AM
Re: Need to extract info from a log file
|
Howard Bullock
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 ]
|
|
Top
|
|
|
|
#32921 - 2002-11-20 07:06 PM
Re: Need to extract info from a log file
|
anthonyl
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
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
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
Anthony.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 484 anonymous users online.
|
|
|