Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing Line of Text Based On A Condition

Status
Not open for further replies.

scripter73

Programmer
Apr 18, 2001
421
US
Hi,

I've written a script that reads a log file. One input line of this log file is as follows:

10.11.130.80 - - [01/May/2001:13:52:59 -0600] "GET /insuredacct/index.cfm HTTP/1.0" 200 355

I'm trying to split up this one string into multiple string variables to be used later to populate a database.

However, I'm a little stumped on how to read a portion of the buffer, stop reading when I find a space, assign what I've read so far to a string variable, then pick back up reading where I left off.

For example, here's how I want my assignment:

strIP = 10.11.130.80
strId = -
strUser = -
strTime = [01/May/2001:13:52:59 -0600]
strRequest = "GET /insuredacct/index.cfm HTTP/1.0"
strResult = 200
strBytes = 355


Here's the code I have, but so far I'm only able to read an entire line of my file and determine if I have a '.' in the line.

<%
LogFile = &quot;d:\inetpub\
Set LogFileObj = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set LogTextFile = LogFileObj.OpenTextFile(LogFile)

dim strBuffer
dim strIP, strID, strUser, strTime, strRequest, strResult, strBytes

strBuffer=LogTextFile.Readline


'***********************************************
' BEGINNING TO SPLIT UP THE FILE INTO VARIABLES
'***********************************************
'determine if there's a . in the buffer
if instr(strBuffer,&quot;.&quot;) then
response.write &quot;<br>&quot; & &quot;Contains a '.' .&quot; & &quot;<br>&quot;
else
response.write &quot;<br>&quot; & &quot;Does not contain a '.' .&quot; & &quot;<br>&quot;
end if

%>


Any help anyone can provide would be much appreciated.

Thanks,
scripter73
 
dim theArray(), theString

theString = &quot;10.11.130.80 - - [01/May/2001:13:52:59 -0600] GET /insuredacct/index.cfm HTTP/1.0 200 355&quot;

theArray = split(theString, &quot; &quot;)

will give you an array with each element containing the successive bits of that string minus the spaces -- i.e. you are splitting the string with a space as the delimeter.

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top