[Tutor] Re: Incrementing a line?

Shantanoo Mahajan python at dhumketu.cjb.net
Thu Dec 11 08:26:35 EST 2003


+++ Jim Boone [09-12-03 11:54 +0000]:
| Howdy all, i hope this is the right list for my query, pythons a bit new 
| to me, and I'm trying dto something that I can't figure out:
| 
| for s in userlog.readlines():
|            for word in s.split():
|                if word == ("19(Constraint"):
|                    constraintlog.write(s + "\n")
|                    print "\n\n*****Constraint Violations exist!!*****\n\n"
|        constraintlog.close()
| 
| Is a section of code i have, it reads a log file and cranks out a log 
| file on a certain condition, I can get it to write out the same line 
| which is in the original log file, which is useful, but, what would be 
| much more useful is if i could write out the line thats 10 lines after 
| the "19(Constraint", because it's more pertinent, but of course s+10 is 
| stupidly wrong.
| 
| Any help appreciated, Thanks!
| 
| -- 
| Jim Boone

Well, if you are using *nix, then

grep -A no_of_lines_after_match word_to_be_matched logfile > contraintlog

Shantanoo



More information about the Tutor mailing list