[Tutor] File parse
Tino Dai
tinoloc at gmail.com
Thu Jul 19 20:40:58 CEST 2007
On 7/18/07, Tiger12506 <keridee at jayco.net> wrote:
>
> >I sent a sample of the file "testin.txt" in the last email. Here are the
> > lines themsevles:
>
> Oh! Sorry. I didn't look in the attachments - I expected the lines in the
> email. My mistake.
> Try this ~~ :-P
>
>
> ##############################
> import re
>
> infile = open("testin.txt","r")
> outfile = open("out.txt","w")
>
> patt = re.compile(r".*src=([\d\.]*) dst=([\d\.]*).*")
>
> for line in infile:
> m = patt.match(line)
> if m:
> outfile.write("src=%s dst=%s\n"%m.groups())
>
> infile.close()
> outfile.close()
> #############################
>
> Seeing the input file makes me wonder if regular expressions is over kill
> in
> this instance.
>
> JS
Hi there,
If you are looking for one ip address, and only one ip address, you
might want to consider:
for line in input_file:
if "10.52.10.10" in line:
outfile.writeline(line)
outfile.close()
Is that what you want?
-Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070719/d716113e/attachment-0001.html
More information about the Tutor
mailing list