aboutsummaryrefslogtreecommitdiff
path: root/test/Scripts/prcontext.py
blob: b91f618c57bb1af4d6c5b753bd90c7215cfacffd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#
# Usage:
# prcontext <pattern> <# lines of context>
#

import sys

#
# Get the arguments
#
pattern=sys.argv[1]
num=int(sys.argv[2])

#
# Get all of the lines in the file.
#
lines=sys.stdin.readlines()

index=0
for line in lines:
  if ((line.find(pattern)) != -1):
    if (index-num < 0):
      bottom=0
    else:
      bottom=index-num
    for output in lines[bottom:index+num+1]:
      print output[:-1]
  index=index+1