Skip to main content

Grep implementation with replace

Project description

Build Status
Codacy Badge


Fast grep implementation in python, with replace features

usage: [-h] [-v] [-x EXTENSIONS [EXTENSIONS ...]] [-r] [-l] [-i]
                   [-g REPLACE_EXPR] [-f REPLACE_EXPR]
                   expression [file]

file search and replace with regular expressions

positional arguments:
  expression            regular expression
  file                  file path (or directory if -r is used)

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
                        restrict search to file extensions (ex: .py .txt .java
  -r, --recursive       recursively search in path
  -l, --list            list files matching pattern
  -i, --inplace         update the file inplace (with -g or -f)
  -g REPLACE_EXPR, --replace-global REPLACE_EXPR
                        global replacement expression
  -f REPLACE_EXPR, --replace-first REPLACE_EXPR
                        first occurrence replacement expression

Why fast?

Because it exclusively uses generators, reptile never allocates big lists, it always processes one line in one file at a time. you can do a search on big files and large directories like / recursively without memory overhead.


Search "import" in ./ :

$ ./ "import" ./
import re
import os
import sys
    import argparse

Replacement & easy grouping with python re.sub syntax :

$ "\[(.*)\]\((.*)\)" -g "<a href=\"\2\">\1</a>" | diff -u -
---   2016-04-19 22:37:20.000000000 +0200
+++ -   2016-04-25 14:54:24.000000000 +0200
@@ -1,4 +1,4 @@
+!<a href="">Agera</a>
 Reactive Programming for Android


import greptile

# Replace "import" by "export" from dir `./`, in all files and these extensions: .py, .xml, .java
greptile.replace('import', 'export', './', '.py', '.xml', '.java')

# Return filenames of all files containing the text "import" from dir `./` and .py, .xml, .java
my_list = greptile.grep_rl('import', './', '.py', '.xml', '.java')

# same as calling replace()
greptile.sed_i(my_list, 'import', 'export')

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Greptile, version 0.9
Filename, size File type Python version Upload date Hashes
Filename, size Greptile-0.9.tar.gz (2.7 kB) File type Source Python version None Upload date Hashes View
Filename, size Greptile-0.9-py2.py3-none-any.whl (4.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page