Best way to parse log file

Post Reply
mjacobson
Posts: 204
Joined: Fri Feb 08, 2002 3:35 pm

Best way to parse log file

Post by mjacobson »

I have a file with values separated by a ||.

Sample line:
45f74f4214||yahoo.com||readya||p||linhost2o||D||/yb/jaa/jaa2007/jaa_1315.htm||6c0bc5bd82fb5fc1b11b9d4811fffaeb||6D432445bd82fb5fc1b11b9d4811fffaeb

Not all values maybe present so if something was missing but the separators will be there. I have tried the following code but it doesn't always work.

<if $line ne "">
<$i=1>
<split "|{2}" $line><$parts=$ret>
<loop $parts><$part=$parts>
<SWITCH $i>
<CASE eq 1><$ID=$part>
<CASE eq 2><$USERDOMAIN=$part>
<CASE eq 3><$USERID=$part>
<CASE eq 4><$LOGINTYPE=$part>
<CASE eq 5><$REMOTEHOST=$part>
<CASE eq 6><$FILETYPE=$part>
<CASE eq 7><$FILENAME=$part>
<CASE eq 8><$DOCID=$part>
<CASE eq 9><$IMAGEID=$part>
</SWITCH>
<$i=($i+1)>
</loop>
User avatar
John
Site Admin
Posts: 2622
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

Best way to parse log file

Post by John »

How does it not work?

The simplest thing maybe to use <timport> with

csv ||

as the format specifier in the schema.

Also you can use $loop (0-based) or $next (1-based) in the loop instead if $i for switching on.
John Turnbull
Thunderstone Software
Post Reply