467,116 Members | 1,198 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,116 developers. It's quick & easy.

ReadLine and redex?

rjb
Hi there

I have a text file which looks like the one below.
I'm trying to write a program which will go through each of those lines
(for each section separated by an empty line) and give me:

Day, Month, HH, MM, SS, Year, User-Name, Acct-Multi-Session-Id,
Acct-Input-Gigawords,
Acct-Output-Gigawords, Acct-Input-Octets, Acct-Output-Octets.

I'll work on it today, but if somebody could point me in right directions I
would really appreciate it.

Thank you,
rjb
Tue Sep 28 09:32:03 2004
Acct-Status-Type = Interim-Update
User-Name = "00079326AAC8"
NAS-IP-Address = 192.168.10.40
Service-Type = DATA
Acct-Multi-Session-Id = "147859"
Acct-Session-Id = "3"
Acct-Delay-Time = 0
Event-Timestamp = 1096363922
Acct-Session-Time = 8428
Acct-Input-Gigawords = 0
Acct-Output-Gigawords = 0
Acct-Input-Octets = 90471
Acct-Output-Octets = 434245
Acct-Terminate-Cause = 0
Framed-IP-Address = 0.0.0.0
Acct-Input-Packets = 0
Acct-Output-Packets = 0
NAS-Port-Type = Async
NAS-Port-Id = 0

Tue Sep 28 09:50:28 2004
Acct-Status-Type = Start
User-Name = "0007933B22B9"
NAS-IP-Address = 192.168.10.40
Service-Type = DATA
Acct-Multi-Session-Id = "147912"
Acct-Session-Id = "3"
Acct-Delay-Time = 0
Event-Timestamp = 1096365027
Framed-IP-Address = 0.0.0.0
Acct-Input-Packets = 0
Acct-Output-Packets = 0
NAS-Port-Type = Async
NAS-Port-Id = 0

Tue Sep 28 10:01:42 2004
Acct-Status-Type = Interim-Update
User-Name = "0007933B22B9"
NAS-IP-Address = 192.168.10.40
Service-Type = DATA
Acct-Multi-Session-Id = "147912"
Acct-Session-Id = "3"
Acct-Delay-Time = 0
Event-Timestamp = 1096365701
Acct-Session-Time = 674
Acct-Input-Gigawords = 0
Acct-Output-Gigawords = 0
Acct-Input-Octets = 43003
Acct-Output-Octets = 24106
Acct-Terminate-Cause = 0
Framed-IP-Address = 0.0.0.0
Acct-Input-Packets = 0
Acct-Output-Packets = 0
NAS-Port-Type = Async
NAS-Port-Id = 0xt file wich looks like this....
Nov 16 '05 #1
  • viewed: 2424
Share:
2 Replies
Hi,

You can assumulate read lines in a StringCollection until an empty line is
reached. When the empty line is reached, process all accumulated lines and
clear the collection.
You can indeed parse the lines with Regex, extract the values of interest
and store them somewhere.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"rjb" <RJB@no_spam_VP.PL> wrote in message news:cl**********@news.onet.pl...
Hi there

I have a text file which looks like the one below.
I'm trying to write a program which will go through each of those lines
(for each section separated by an empty line) and give me:

Day, Month, HH, MM, SS, Year, User-Name, Acct-Multi-Session-Id,
Acct-Input-Gigawords,
Acct-Output-Gigawords, Acct-Input-Octets, Acct-Output-Octets.

I'll work on it today, but if somebody could point me in right directions
I
would really appreciate it.

Thank you,
rjb
Tue Sep 28 09:32:03 2004
Acct-Status-Type = Interim-Update
User-Name = "00079326AAC8"
NAS-IP-Address = 192.168.10.40
Service-Type = DATA
Acct-Multi-Session-Id = "147859"
Acct-Session-Id = "3"
Acct-Delay-Time = 0
Event-Timestamp = 1096363922
Acct-Session-Time = 8428
Acct-Input-Gigawords = 0
Acct-Output-Gigawords = 0
Acct-Input-Octets = 90471
Acct-Output-Octets = 434245
Acct-Terminate-Cause = 0
Framed-IP-Address = 0.0.0.0
Acct-Input-Packets = 0
Acct-Output-Packets = 0
NAS-Port-Type = Async
NAS-Port-Id = 0

Tue Sep 28 09:50:28 2004
Acct-Status-Type = Start
User-Name = "0007933B22B9"
NAS-IP-Address = 192.168.10.40
Service-Type = DATA
Acct-Multi-Session-Id = "147912"
Acct-Session-Id = "3"
Acct-Delay-Time = 0
Event-Timestamp = 1096365027
Framed-IP-Address = 0.0.0.0
Acct-Input-Packets = 0
Acct-Output-Packets = 0
NAS-Port-Type = Async
NAS-Port-Id = 0

Tue Sep 28 10:01:42 2004
Acct-Status-Type = Interim-Update
User-Name = "0007933B22B9"
NAS-IP-Address = 192.168.10.40
Service-Type = DATA
Acct-Multi-Session-Id = "147912"
Acct-Session-Id = "3"
Acct-Delay-Time = 0
Event-Timestamp = 1096365701
Acct-Session-Time = 674
Acct-Input-Gigawords = 0
Acct-Output-Gigawords = 0
Acct-Input-Octets = 43003
Acct-Output-Octets = 24106
Acct-Terminate-Cause = 0
Framed-IP-Address = 0.0.0.0
Acct-Input-Packets = 0
Acct-Output-Packets = 0
NAS-Port-Type = Async
NAS-Port-Id = 0xt file wich looks like this....


Nov 16 '05 #2
rjb

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:Om****************@TK2MSFTNGP12.phx.gbl...
Hi,

You can assumulate read lines in a StringCollection until an empty line is
reached. When the empty line is reached, process all accumulated lines and
clear the collection.
You can indeed parse the lines with Regex, extract the values of interest
and store them somewhere.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"rjb" <RJB@no_spam_VP.PL> wrote in message

news:cl**********@news.onet.pl...
Hi there

I have a text file which looks like the one below.
I'm trying to write a program which will go through each of those lines
(for each section separated by an empty line) and give me:

Day, Month, HH, MM, SS, Year, User-Name, Acct-Multi-Session-Id,
Acct-Input-Gigawords,
Acct-Output-Gigawords, Acct-Input-Octets, Acct-Output-Octets.

I'll work on it today, but if somebody could point me in right directions I
would really appreciate it.

Thank you,
rjb
Tue Sep 28 09:32:03 2004
Acct-Status-Type = Interim-Update
User-Name = "00079326AAC8"
NAS-IP-Address = 192.168.10.40
Service-Type = DATA
Acct-Multi-Session-Id = "147859"
Acct-Session-Id = "3"
Acct-Delay-Time = 0
Event-Timestamp = 1096363922
Acct-Session-Time = 8428
Acct-Input-Gigawords = 0
Acct-Output-Gigawords = 0
Acct-Input-Octets = 90471
Acct-Output-Octets = 434245
Acct-Terminate-Cause = 0
Framed-IP-Address = 0.0.0.0
Acct-Input-Packets = 0
Acct-Output-Packets = 0
NAS-Port-Type = Async
NAS-Port-Id = 0

Tue Sep 28 09:50:28 2004
Acct-Status-Type = Start
User-Name = "0007933B22B9"
NAS-IP-Address = 192.168.10.40
Service-Type = DATA
Acct-Multi-Session-Id = "147912"
Acct-Session-Id = "3"
Acct-Delay-Time = 0
Event-Timestamp = 1096365027
Framed-IP-Address = 0.0.0.0
Acct-Input-Packets = 0
Acct-Output-Packets = 0
NAS-Port-Type = Async
NAS-Port-Id = 0

Tue Sep 28 10:01:42 2004
Acct-Status-Type = Interim-Update
User-Name = "0007933B22B9"
NAS-IP-Address = 192.168.10.40
Service-Type = DATA
Acct-Multi-Session-Id = "147912"
Acct-Session-Id = "3"
Acct-Delay-Time = 0
Event-Timestamp = 1096365701
Acct-Session-Time = 674
Acct-Input-Gigawords = 0
Acct-Output-Gigawords = 0
Acct-Input-Octets = 43003
Acct-Output-Octets = 24106
Acct-Terminate-Cause = 0
Framed-IP-Address = 0.0.0.0
Acct-Input-Packets = 0
Acct-Output-Packets = 0
NAS-Port-Type = Async
NAS-Port-Id = 0xt file wich looks like this....


Hi Dmitriy

Thank you for your post. Your suggestions are very close to my approach, but
perhaps my implementation
is very poor. I'm not too strong with C#. Also, regular expressions are
very, very new to me.

Here is a piece of code I was playing with today. Could you please check if
that's the correct way.

At that stage I'm just finding "User-Name" I'm planning to add regular
expression for each string I want to extract.

Also, I haven't tested in fully, but this code "while (reader.Peek()
!= -1)"
suppose to run my loop until EOF, but I think it loops endless.

Thank you,
rjb

StreamReader reader = new StreamReader("C:\\radius.txt");
StringBuilder sb = new StringBuilder();

string text = string.Empty;

Regex regEx = new Regex(@"(?<=User-Name = )\""([^\""]+)\""",
RegexOptions.None);

while (reader.Peek() != -1)
{
do
{
text = reader.ReadLine();
sb.Append(text);
}
while(text != "");

Match mt = regEx.Match(sb.ToString());
string name = mt.Groups[1].ToString();
Console.WriteLine(name); //this displays 00079326AAC8,
so it work!
}
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Russell E. Owen | last post: by
reply views Thread by John C. Worsley | last post: by
1 post views Thread by Jian Qiu | last post: by
4 posts views Thread by David Bear | last post: by
3 posts views Thread by PointMan | last post: by
reply views Thread by 7stud | last post: by
6 posts views Thread by Sean Davis | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.