Skip to content

string replacement tool which uses a regular expression.

License

Notifications You must be signed in to change notification settings

shimt/rereplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rereplace

rereplace is a string replacement tool which uses a regular expression.
Since it was tired from mass-producing an one line sed script tutorial, it created.

Description

This is is a string replacement tool which uses a regular expression.

  • input is STDIN and an output is STDOUT.
  • PATTERN and REPLACEMENT can also be read from a files.
cat textfile.txt | sed -re 's/^([^\t\n]*)\t([^\t\n]*)\t([^\t\n]*)\t([^\t\n]*)$/\1,\4/g'
cat textfile.txt | rereplace.py '^([^\t\n]*)\t([^\t\n]*)\t([^\t\n]*)\t([^\t\n]*)$' '\1,\4'
cat > pattern.txt <<EOB
(?x)
^
([^\t\n]*)\t
([^\t\n]*)\t
([^\t\n]*)\t
([^\t\n]*)
$
EOB
echo -n '\1,\2' > replacement.txt
cat textfile.txt | rereplace.py @pattern.txt @replacement.txt

Requirement

Python 3.x

Usage

usage: rereplace.py [-h] [--re-ascii] [--re-debug] [--re-ignorecase]
                    [--re-locale] [--re-multiline] [--re-dotall]
                    [--re-verbose] [--multiline]
                    PATTERN REPLACEMENT

regex replacing tool

positional arguments:
  PATTERN
  REPLACEMENT

optional arguments:
  -h, --help           show this help message and exit
  --multiline          enable multi-line mode (read all the lines into a
                       memory)

regex matching flags:
  --re-ascii, -a       re.ASCII
  --re-debug           re.DEBUG
  --re-ignorecase, -i  re.IGNORECASE
  --re-locale, -l      re.LOCALE
  --re-multiline, -m   re.MULTILINE
  --re-dotall, -s      re.DOTALL
  --re-verbose, -x     re.VERBOSE

Install

copy rereplace.py. or python3 setup.py install or python3 setup.py py2exe (require py2exe)

Licence

MIT

About

string replacement tool which uses a regular expression.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages