New python script that print a specified number of lines surrounding a
authorJohn Criswell <criswell@uiuc.edu>
Mon, 2 Aug 2004 22:28:50 +0000 (22:28 +0000)
committerJohn Criswell <criswell@uiuc.edu>
Mon, 2 Aug 2004 22:28:50 +0000 (22:28 +0000)
located pattern.
In other words, grep -C for Solaris.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15425 91177308-0d34-0410-b5e6-96231b3b80d8

test/Scripts/prcontext.py [new file with mode: 0755]

diff --git a/test/Scripts/prcontext.py b/test/Scripts/prcontext.py
new file mode 100755 (executable)
index 0000000..b91f618
--- /dev/null
@@ -0,0 +1,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
+