summaryrefslogtreecommitdiffstats
path: root/Lib/lib-old
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-10-22 20:44:58 (GMT)
committerGuido van Rossum <guido@python.org>1997-10-22 20:44:58 (GMT)
commit8566e474b4e54956a14f056173692c834f40f1a5 (patch)
treec58d8d2aa57e4bb0249eb2f56ad6621a078c5848 /Lib/lib-old
parentb49144244c930603e8eb54880874c37adcff1440 (diff)
downloadcpython-8566e474b4e54956a14f056173692c834f40f1a5.zip
cpython-8566e474b4e54956a14f056173692c834f40f1a5.tar.gz
cpython-8566e474b4e54956a14f056173692c834f40f1a5.tar.bz2
Added pgrep() function, which is like grep/egrep/emgrep but uses Perl
syntax, by virtue of the new re module.
Diffstat (limited to 'Lib/lib-old')
-rw-r--r--Lib/lib-old/grep.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/lib-old/grep.py b/Lib/lib-old/grep.py
index f466651..423c065 100644
--- a/Lib/lib-old/grep.py
+++ b/Lib/lib-old/grep.py
@@ -38,6 +38,24 @@ def ggrep(syntax, pat, files):
showline(filename, lineno, line, prog)
fp.close()
+def pgrep(pat, *files):
+ if len(files) == 1 and type(files[0]) == type([]):
+ files = files[0]
+ global opt_show_filename
+ opt_show_filename = (len(files) != 1)
+ import re
+ prog = re.compile(pat)
+ for filename in files:
+ fp = open(filename, 'r')
+ lineno = 0
+ while 1:
+ line = fp.readline()
+ if not line: break
+ lineno = lineno + 1
+ if prog.search(line):
+ showline(filename, lineno, line, prog)
+ fp.close()
+
def showline(filename, lineno, line, prog):
if line[-1:] == '\n': line = line[:-1]
if opt_show_lineno: