blob: b91f618c57bb1af4d6c5b753bd90c7215cfacffd [file] [log] [blame]
John Criswell21eccb62004-08-02 22:28:50 +00001#
2# Usage:
3# prcontext <pattern> <# lines of context>
4#
5
6import sys
7
8#
9# Get the arguments
10#
11pattern=sys.argv[1]
12num=int(sys.argv[2])
13
14#
15# Get all of the lines in the file.
16#
17lines=sys.stdin.readlines()
18
19index=0
20for line in lines:
21 if ((line.find(pattern)) != -1):
22 if (index-num < 0):
23 bottom=0
24 else:
25 bottom=index-num
26 for output in lines[bottom:index+num+1]:
27 print output[:-1]
28 index=index+1
29