diff options
author | John Criswell <criswell@uiuc.edu> | 2004-08-02 22:28:50 +0000 |
---|---|---|
committer | John Criswell <criswell@uiuc.edu> | 2004-08-02 22:28:50 +0000 |
commit | 21eccb6563eb467d8dc7ab8cb7c3cccad55c38a5 (patch) | |
tree | 550da32a39826369e2de970269bb8087c7557a67 /test/Scripts | |
parent | 9b87287e7df82dd82570396cdba0da42eb4fca93 (diff) |
New python script that print a specified number of lines surrounding a
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
Diffstat (limited to 'test/Scripts')
-rwxr-xr-x | test/Scripts/prcontext.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/Scripts/prcontext.py b/test/Scripts/prcontext.py new file mode 100755 index 0000000000..b91f618c57 --- /dev/null +++ b/test/Scripts/prcontext.py @@ -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 + |