473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
2 2631
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Russell E. Owen | last post by:
At one time, mixing for x in file and readline was dangerous. For example: for line in file: # read some lines from a file, then break nextline = readline() # bad would not do what a naive...
0
by: John C. Worsley | last post by:
I've got an extremely inscrutable problem here using Perl's Term::ReadLine::Gnu module. I'm using Perl 5.8.0, readline 4.3 and Term::ReadLine::Gnu 1.14. The problem is specific to catching INT...
1
by: Jian Qiu | last post by:
Hi, I tried to install python2.4.2. Unfortunately building 'readline' extension failed. Here is what I got: (It is a bit long. If you are impatient, please look at the end where it reports the...
4
by: David Bear | last post by:
I built python 2.4.2 for suse linux 9.3. I configured it to be a separate instance of python from the version packaged with suse. Now when I start it I get an error: python Python 2.4.2 (#4,...
3
by: PointMan | last post by:
what i know is... while ((currentStr = sr.ReadLine()) != null) { in this area, can i get next ReadLine Value of currentStr } best regard,,
0
by: 7stud | last post by:
Hi, 1) Does this make any sense: """ Thus, the loop: for line in f: iterates on each line of the file. Due to buffering issues,
6
by: Sean Davis | last post by:
I have a large file that I would like to transform and then feed to a function (psycopg2 copy_from) that expects a file-like object (needs read and readline methods). I have a class like so: ...
0
by: Akira Kitada | last post by:
Hi list, I was trying to build Python 2.6 on FreeBSD 4.11 and found it failed to build some of the modules. """ Failed to find the necessary bits to build these modules: _bsddb ...
0
by: M.-A. Lemburg | last post by:
On 2008-10-25 08:39, Akira Kitada wrote: Please post a bug report on python.org about these failures. The multiprocessing module is still fairly new and obviously needs more fine tuning for...
0
by: Akira Kitada | last post by:
Hi Marc-Andre, Thanks for the suggestion. I opened a ticket for this issue: http://bugs.python.org/issue4204 Now I understand the state of the multiprocessing module, but it's too bad to see...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.