Re: extract certain values from file with re

2006-10-07 Thread Fabian Braennstroem
Hi to all, thanks a lot! I am pretty sure your ideas help :-) Greetings! Fabian -- http://mail.python.org/mailman/listinfo/python-list

extract certain values from file with re

2006-10-06 Thread Fabian Braennstroem
Hi, I would like to remove certain lines from a log files. I had some sed/awk scripts for this, but now, I want to use python with its re module for this task. Actually, I have two different log files. The first file looks like: ... 'some text' ... ITER I-

Re: extract certain values from file with re

2006-10-06 Thread Bernard
Hi Fabian, I'm still a youngster in Python but I think I can help with the extracting data from the log file part. As I'm seeing it right now, the only character separating the numbers below is the space character. You could try splitting all the lines by that character starting from the NO

Re: extract certain values from file with re

2006-10-06 Thread johnzenger
Can you safely assume that the lines you want to extract all contain numbers, and that the lines you do not wish to extract do not contain numbers? If so, you could just use the Linux grep utility: grep '[0123456789]' filename Or, in Python: import re inf = file(your-filename-here.txt) outf =

Re: extract certain values from file with re

2006-10-06 Thread bearophileHUGS
Fabian Braennstroem: A more difficult log file looks like: ... With my sed/awk/grep/gnuplot script I would extract the values in the 'U-Mom' row using grep and print a certain column (e.g. 'Max Res') to a file and print it with gnuplot. Maybe I have to remove those '|' using sed before...

Re: extract certain values from file with re

2006-10-06 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: a fine solution component for the second problem Use his solution like: datafile = open(data_file_name, 'r') for line in datafile: if 'U-Mom' in line: print float(line.split(|)[4]) datafile.close() For the earlier problem:

Re: extract certain values from file with re

2006-10-06 Thread Paul McGuire
Fabian Braennstroem [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, I would like to remove certain lines from a log files. I had some sed/awk scripts for this, but now, I want to use python with its re module for this task. Actually, I have two different log files. The first

Re: extract certain values from file with re

2006-10-06 Thread Paddy
Fabian Braennstroem wrote: Hi, I actually want to extract the lines with the numbers, write them to a file and finally use gnuplot for plotting them. A nicer and more python way would be to extract those numbers, write them into an array according to their column and plot those

Re: extract certain values from file with re

2006-10-06 Thread Matteo
Fabian Braennstroem wrote: Hi, I would like to remove certain lines from a log files. I had some sed/awk scripts for this, but now, I want to use python with its re module for this task. Actually, I have two different log files. The first file looks like: ... 'some text' ...

Re: extract certain values from file with re

2006-10-06 Thread hanumizzle
On 6 Oct 2006 13:16:13 -0700, Matteo [EMAIL PROTECTED] wrote: Coming from C++, using exceptions in this way still feels a bit creepy to me, but I've been assured that this is very pythonic, and I'm slowly adopting this style in my python code. Parsing the line can be easy too: