Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 25th, 2007, 07:28 AM
Authorized User
 
Join Date: Jan 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Parsing a log file using regular expressions

I have a text file say log file. i have to extract all the characters between "<" sign and ">" sign.
i.e. between <> and put it into the database and log file is of kind

Sun, 24 Jun 2007 21:49:49 GMT: Received request </abc/abc.gif>, from <111.1.11.11>:<1111> at domain <localhost/abc.net>
Sun, 24 Jun 2007 21:49:49 GMT: UserName <abc>, Proxy <localhost-80>, URN <http://abc/abc.gif>
Sun, 24 Jun 2007 21:49:49 GMT: Processing Proxy request
Sun, 24 Jun 2007 21:49:50 GMT: Sending Msg <111> from Proxy Reader <1111111111> for URL <http://abc.abc/>with Params <> <abc>

Sun, 24 Jun 2007 21:49:50 GMT: Named pipe <\\.\pipe\1111111111> started for request <http://abc.abc/>

Sun, 24 Jun 2007 21:49:50 GMT: Received request </abc/abc.gif>, from <111.1.11.11>:<1111> at domain <localhost/abc.net>

Sun, 24 Jun 2007 21:49:50 GMT: UserName <abc>, Proxy <localhost-80>, URN <http://abc/abc.gif>

Sun, 24 Jun 2007 21:49:50 GMT: Processing Proxy request

Sun, 24 Jun 2007 21:49:52 GMT: Received Msg <222> for URL <http://abc.abc/>
Sun, 24 Jun 2007 21:49:52 GMT: Status: 200 OK, Reminder: Server: Microsoft-IIS/5.1

X-Powered-By: ASP.NET
Date: Mon, 25 Jun 2007 04:48:33 GMT

Content-Type: text/html

Accept-Ranges: bytes

Last-Modified: Thu, 22 Mar 2007 05:29:17 GMT

Sun, 24 Jun 2007 21:49:52 GMT: Last chunck read from pipe \\.\pipe\1111111111 for <http://abc.abc/>: <963>

Sun, 24 Jun 2007 21:49:52 GMT: Closing pipe <\\.\pipe\1111111111> for url <http://abc.abc/>


 and i want to parse this file and extract and put the information from <> sign into the database
  i had followed following link for file parsing
and instead of putting the info in dataset i m putting it into database.
Now my problem is my log file is of above format and i have to parse all the info within <>

I m using C# 1.1 version
does anybody have any idea or suggestions?
Thanks in advance





 
Old July 9th, 2007, 05:25 AM
Authorized User
 
Join Date: Dec 2004
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DZukiewicz
Default

Use a Regex.Match() for "<.*?>". You'll get the following results:

---
</abc/abc.gif>
<111.1.11.11>
<1111>
<localhost/abc.net>
<abc>
<localhost-80>
<http://abc/abc.gif>
<111>
<1111111111>
<http://abc.abc/>
<>
<abc>
<\\.\pipe\1111111111>
<http://abc.abc/>
</abc/abc.gif>
<111.1.11.11>
<1111>
<localhost/abc.net>
<abc>
<localhost-80>
<http://abc/abc.gif>
<222>
<http://abc.abc/>
<http://abc.abc/>
<963>
<\\.\pipe\1111111111>
<http://abc.abc/>
----

Is this what you wanted?

Regards,

Dominic





Similar Threads
Thread Thread Starter Forum Replies Last Post
Do I need regular expressions..? ypomonh XSLT 2 May 20th, 2007 05:09 PM
Help with Regular Expressions WestRowOps Other Programming Languages 1 May 18th, 2007 05:34 AM
Regular expressions on C# hideway C# 2 November 27th, 2006 05:08 PM
I need some help in regular expressions! marwaesmat Perl 2 March 7th, 2006 05:22 PM
Regular Expressions Dave Doknjas C# 1 August 9th, 2003 12:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.