ReadLine and redex?

R

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....
 
D

Dmitriy Lapshin [C# / .NET MVP]

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.
 
R

rjb

Dmitriy Lapshin said:
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

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!
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top