Page 1 of 1

Is this doable or not?

Posted: 06 Jul 2011 06:29
by renzlo
Hi everyone,

I am wondering if this is doable.

I have a log file with these contents:

source.log

Code: Select all

basic: Applet initialized
webServer= http://webcodingtpp.nl.post.tnt:80/servlet/TPP-ProductcoderenServlet
[05 Jul 2011 01:59:04.151] Getting the image from the server:3768 msec.
[05 Jul 2011 01:59:04.151] Queueing the image:               389 msec.
[05 Jul 2011 01:59:04.151] Preparing/scaling the image:      529 msec.
[05 Jul 2011 01:59:04.151] Displaying the image:             0 msec.
[05 Jul 2011 01:59:04.151] Coding the image:                 2374 msec.
[05 Jul 2011 01:59:04.151] --------------------------------
[05 Jul 2011 01:59:04.151] requestGET = http://webcodingtpp.nl.post.tnt:80/servlet/TPP-ProductcoderenServlet?letterId=[05 Jul 2011 04:38:45.322] setResult()
[05 Jul 2011 04:38:45.322]   result  = 1
[05 Jul 2011 04:38:45.322]   country = NL
[05 Jul 2011 04:38:45.322]   pc      = 5140WR
[05 Jul 2011 04:38:45.322]   hnr     = 25000
[05 Jul 2011 04:38:45.322]   olHnr   = 25000
[05 Jul 2011 04:38:45.322]   olExt   = 
[05 Jul 2011 04:38:45.322] ---Timing-----------------------
[05 Jul 2011 04:38:45.322] Getting the image from the server:1868 msec.
[05 Jul 2011 04:38:45.322] Queueing the image:               234 msec.
[05 Jul 2011 04:38:45.322] Preparing/scaling the image:      109 msec.
[05 Jul 2011 04:38:45.322] Displaying the image:             0 msec.
[05 Jul 2011 04:38:45.322] Coding the image:                 3813 msec.
[05 Jul 2011 04:38:45.322] --------------------------------
webServer= http://webcodingtpp.nl.post.tnt:80/servlet/TPP-BestemmingscoderenServlet
[05 Jul 2011 01:59:04.151] Getting the image from the server:3768 msec.
[05 Jul 2011 01:59:04.151] Queueing the image:               389 msec.
[05 Jul 2011 01:59:04.151] Preparing/scaling the image:      529 msec.
[05 Jul 2011 01:59:04.151] Displaying the image:             0 msec.
[05 Jul 2011 01:59:04.151] Coding the image:                 2374 msec.
[05 Jul 2011 01:59:04.151] --------------------------------
[05 Jul 2011 01:59:04.151] requestGET = http://webcodingtpp.nl.post.tnt:80/servlet/TPP-ProductcoderenServlet?letterId=[05 Jul 2011 04:38:45.322] setResult()
[05 Jul 2011 04:38:45.322]   result  = 1
[05 Jul 2011 04:38:45.322]   country = NL
[05 Jul 2011 04:38:45.322]   pc      = 5140WR
[05 Jul 2011 04:38:45.322]   hnr     = 25000
[05 Jul 2011 04:38:45.322]   olHnr   = 25000
[05 Jul 2011 04:38:45.322]   olExt   = 
[05 Jul 2011 04:38:45.322] ---Timing-----------------------
[05 Jul 2011 04:38:45.322] Getting the image from the server:1868 msec.
[05 Jul 2011 04:38:45.322] Queueing the image:               234 msec.
[05 Jul 2011 04:38:45.322] Preparing/scaling the image:      109 msec.
[05 Jul 2011 04:38:45.322] Displaying the image:             0 msec.
[05 Jul 2011 04:38:45.322] Coding the image:                 3813 msec.
[05 Jul 2011 04:38:45.322] --------------------------------
webServer= http://webcodingtpp.nl.post.tnt:80/servlet/TPP-ProductcoderenServlet
[05 Jul 2011 01:59:04.151] Getting the image from the server:3768 msec.
[05 Jul 2011 01:59:04.151] Queueing the image:               389 msec.
[05 Jul 2011 01:59:04.151] Preparing/scaling the image:      529 msec.
[05 Jul 2011 01:59:04.151] Displaying the image:             0 msec.
[05 Jul 2011 01:59:04.151] Coding the image:                 2374 msec.
[05 Jul 2011 01:59:04.151] --------------------------------
[05 Jul 2011 01:59:04.151] requestGET = http://webcodingtpp.nl.post.tnt:80/servlet/TPP-ProductcoderenServlet?letterId=[05 Jul 2011 04:38:45.322] setResult()
[05 Jul 2011 04:38:45.322]   result  = 1
[05 Jul 2011 04:38:45.322]   country = NY
[05 Jul 2011 04:38:45.322]   pc      = 6666WR
[05 Jul 2011 04:38:45.322]   hnr     = 35000
[05 Jul 2011 04:38:45.322]   olHnr   = 35000
[05 Jul 2011 04:38:45.322]   olExt   = 
[05 Jul 2011 04:38:45.322] ---Timing-----------------------
[05 Jul 2011 04:38:45.322] Getting the image from the server:1868 msec.
[05 Jul 2011 04:38:45.322] Queueing the image:               2354 msec.
[05 Jul 2011 04:38:45.322] Preparing/scaling the image:      1109 msec.
[05 Jul 2011 04:38:45.322] Displaying the image:             10 msec.
[05 Jul 2011 04:38:45.322] Coding the image:                 38513 msec.
[05 Jul 2011 04:38:45.322] --------------------------------


what i am trying to do is to find this line "webServer= http://webcodingtpp.nl.post.tnt:80/serv ... renServlet" and if found it will create a text file with the filename of the last word of the searched line(eg. TPP-ProductcoderenServlet) and will extract the below lines until it reaches a line equal to this "webServer= http://webcodingtpp.nl.post.tnt:80/serv ... renServlet" and will to the same until it reaches the end.

to make it clear, using source above, the output will be like this:

TPP-ProductcoderenServlet.txt

Code: Select all

webServer= http://webcodingtpp.nl.post.tnt:80/servlet/TPP-ProductcoderenServlet
[05 Jul 2011 01:59:04.151] Getting the image from the server:3768 msec.
[05 Jul 2011 01:59:04.151] Queueing the image:               389 msec.
[05 Jul 2011 01:59:04.151] Preparing/scaling the image:      529 msec.
[05 Jul 2011 01:59:04.151] Displaying the image:             0 msec.
[05 Jul 2011 01:59:04.151] Coding the image:                 2374 msec.
[05 Jul 2011 01:59:04.151] --------------------------------
[05 Jul 2011 01:59:04.151] requestGET = http://webcodingtpp.nl.post.tnt:80/servlet/TPP-ProductcoderenServlet?letterId=[05 Jul 2011 04:38:45.322] setResult()
[05 Jul 2011 04:38:45.322]   result  = 1
[05 Jul 2011 04:38:45.322]   country = NL
[05 Jul 2011 04:38:45.322]   pc      = 5140WR
[05 Jul 2011 04:38:45.322]   hnr     = 25000
[05 Jul 2011 04:38:45.322]   olHnr   = 25000
[05 Jul 2011 04:38:45.322]   olExt   = 
[05 Jul 2011 04:38:45.322] ---Timing-----------------------
[05 Jul 2011 04:38:45.322] Getting the image from the server:1868 msec.
[05 Jul 2011 04:38:45.322] Queueing the image:               234 msec.
[05 Jul 2011 04:38:45.322] Preparing/scaling the image:      109 msec.
[05 Jul 2011 04:38:45.322] Displaying the image:             0 msec.
[05 Jul 2011 04:38:45.322] Coding the image:                 3813 msec.
[05 Jul 2011 04:38:45.322] --------------------------------
webServer= http://webcodingtpp.nl.post.tnt:80/servlet/TPP-ProductcoderenServlet
[05 Jul 2011 01:59:04.151] Getting the image from the server:3768 msec.
[05 Jul 2011 01:59:04.151] Queueing the image:               389 msec.
[05 Jul 2011 01:59:04.151] Preparing/scaling the image:      529 msec.
[05 Jul 2011 01:59:04.151] Displaying the image:             0 msec.
[05 Jul 2011 01:59:04.151] Coding the image:                 2374 msec.
[05 Jul 2011 01:59:04.151] --------------------------------
[05 Jul 2011 01:59:04.151] requestGET = http://webcodingtpp.nl.post.tnt:80/servlet/TPP-ProductcoderenServlet?letterId=[05 Jul 2011 04:38:45.322] setResult()
[05 Jul 2011 04:38:45.322]   result  = 1
[05 Jul 2011 04:38:45.322]   country = NY
[05 Jul 2011 04:38:45.322]   pc      = 6666WR
[05 Jul 2011 04:38:45.322]   hnr     = 35000
[05 Jul 2011 04:38:45.322]   olHnr   = 35000
[05 Jul 2011 04:38:45.322]   olExt   = 
[05 Jul 2011 04:38:45.322] ---Timing-----------------------
[05 Jul 2011 04:38:45.322] Getting the image from the server:1868 msec.
[05 Jul 2011 04:38:45.322] Queueing the image:               2354 msec.
[05 Jul 2011 04:38:45.322] Preparing/scaling the image:      1109 msec.
[05 Jul 2011 04:38:45.322] Displaying the image:             10 msec.
[05 Jul 2011 04:38:45.322] Coding the image:                 38513 msec.
[05 Jul 2011 04:38:45.322] --------------------------------


TPP-BestemmingscoderenServlet.txt

Code: Select all

webServer= http://webcodingtpp.nl.post.tnt:80/servlet/TPP-BestemmingscoderenServlet
[05 Jul 2011 01:59:04.151] Getting the image from the server:3768 msec.
[05 Jul 2011 01:59:04.151] Queueing the image:               389 msec.
[05 Jul 2011 01:59:04.151] Preparing/scaling the image:      529 msec.
[05 Jul 2011 01:59:04.151] Displaying the image:             0 msec.
[05 Jul 2011 01:59:04.151] Coding the image:                 2374 msec.
[05 Jul 2011 01:59:04.151] --------------------------------
[05 Jul 2011 01:59:04.151] requestGET = http://webcodingtpp.nl.post.tnt:80/servlet/TPP-ProductcoderenServlet?letterId=[05 Jul 2011 04:38:45.322] setResult()
[05 Jul 2011 04:38:45.322]   result  = 1
[05 Jul 2011 04:38:45.322]   country = NL
[05 Jul 2011 04:38:45.322]   pc      = 5140WR
[05 Jul 2011 04:38:45.322]   hnr     = 25000
[05 Jul 2011 04:38:45.322]   olHnr   = 25000
[05 Jul 2011 04:38:45.322]   olExt   = 
[05 Jul 2011 04:38:45.322] ---Timing-----------------------
[05 Jul 2011 04:38:45.322] Getting the image from the server:1868 msec.
[05 Jul 2011 04:38:45.322] Queueing the image:               234 msec.
[05 Jul 2011 04:38:45.322] Preparing/scaling the image:      109 msec.
[05 Jul 2011 04:38:45.322] Displaying the image:             0 msec.
[05 Jul 2011 04:38:45.322] Coding the image:                 3813 msec.
[05 Jul 2011 04:38:45.322] --------------------------------


is this possible?

thanks in advance.

Re: Is this doable or not?

Posted: 06 Jul 2011 10:09
by dbenham
Not only is it doable, it is bordering on trivial. Some of your past file manipulation questions have been tricky, but this one is about as simple as it gets.

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set infile="source.log"
set "outfile="
for /f "usebackq delims=" %%l in (%infile%) do (
  set ln=%%l
  if "!ln:~0,54!"=="webServer= http://webcodingtpp.nl.post.tnt:80/servlet/" set outfile="!ln:~54!.txt"
  if defined outfile echo !ln!>>!outfile!
)

The code will strip out any blank lines from the output. If needed, there is a technique that preserves blank lines that aGerman used to answer one of your earlier requests.

If the source.log could ever contain a valid line that starts with ; then the FOR /F EOL option has to be set appropriately.

If the file might contain ! then the following slightly more complicated code is needed:

Code: Select all

@echo off
setlocal disableDelayedExpansion
set infile="source.log"
set "outfile="
for /f "usebackq delims=" %%l in (%infile%) do (
  set ln=%%l
  setlocal enableDelayedExpansion
  if "!ln:~0,54!"=="webServer= http://webcodingtpp.nl.post.tnt:80/servlet/" set outfile="!ln:~54!.txt
  if defined outfile (
    echo !ln!>>!outfile!
    for %%f in (!outfile!) do endlocal & set outfile=%%f
  ) else endlocal
)


Dave Benham

Re: Is this doable or not?

Posted: 06 Jul 2011 12:51
by renzlo
thanks Dave, i thought its not that simple, ill try this soon.

Re: Is this doable or not?

Posted: 07 Jul 2011 05:04
by renzlo
Hi Dave,

I have tested you program and it only extract the next 42 lines and it stops.

this is my actual source.log: http://www.mediafire.com/?xhx1c23vey34aj5

Re: Is this doable or not?

Posted: 07 Jul 2011 06:26
by dbenham
Your source.log has 34 instances of the NUL (0x00) character. DOS cannot read past the NUL character.

You need to either fix the code that generated your log to eliminate the NUL, or use a hex editor to find all instances of NUL and replace them with nothing, or the character of your choice.

Or better yet, use a more powerful language to process the file that you have now.

Dave Benham

Re: Is this doable or not?

Posted: 07 Jul 2011 13:52
by renzlo
i see.thanks for your time Dave.

Re: Is this doable or not?

Posted: 07 Jul 2011 14:22
by dbenham
P.S. The code does work to completion once the NUL characters are eliminated.

I used Frhed - Free Hex Editor - available here: http://frhed.sourceforge.net
The help system was broken for me, but an online search showed that I could find and replace a hex byte using <bh00> notation (bh for binary hex).

A hex editor is a handy tool to have in your arsenal.

Dave Benham

Re: Is this doable or not?

Posted: 08 Jul 2011 15:31
by renzlo
thanks for the tip Dave. I have been messing around to do the replacement in batch but no luck. I think hex editor is the only way to do it.