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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting items from logfiles

Status
Not open for further replies.

SenHu

Instructor
Mar 6, 2009
2
US
Someone asked a question in thread329-1466359.

OROGINAL QUESTION
" I need to extract the double quoted text from a logfile. The logfile has the following format.

152.15.112.88:1755 ssl "(CN=Hung\,Bart,CN=Users,DC=company,DC=com)@(LDAP)" "15/Apr/2008:10:26:38.779 -0400" v5 connect 13552

I need to extract and write out the following.

CN=Hung\,Bart,CN=Users,DC=company,DC=com)@(LDAP)
15/Apr/2008:10:26:38.779 -0400

I need to do this line by line."

Here is an answer.

This sample code is written in biterscripting ( for free download ) . The same logic can be followed in other scripting.

Let's assume the logfile is logfile.txt. The code is below.

# START OF CODE
var str log ; cat "logfile.txt" > $log
while ( { sen -r "^\"&\"^" $log } > 0 )
stex -r "^\"&\"^" $log
# END OF CODE

Pretty simple code.

The cat command reads the logfile into a str variable $log.
The sen command counts the remaining "..." pairs in $log.
The stex command extracts the first "..." pair in $log.

Command sen is String ENumerator
Command stex is STring EXtractor
Option -r means Regular expression
&, in Regular expression, means any number of any characters.

There is a Web Log Parsing script (open source) posted at You may find that useful also.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top