getting the line just before or after a pattern searched

bonono at gmail.com bonono at gmail.com
Thu Feb 16 23:52:40 EST 2006


s99999999s2003 at yahoo.com wrote:
> hi
>
> i have a file something like this
>
> abcdefgh
> ijklmnopq
> 12345678
> rstuvwxyz
> .....
> .....
> .....
> 12345678
> .....
>
> whenever i search the file and reach 12345678, how do i get the line
> just above and below ( or more than 1 line above/below) the pattern
> 12345678 and save to variables? thanks

I would try something similar to the pairwise recipe here :

http://www.python.org/doc/2.4.2/lib/itertools-recipes.html




More information about the Python-list mailing list