https://github.com/malthejorgensen/repx
Python regular expression file transformer
https://github.com/malthejorgensen/repx
command-line-tool data-analysis text-processing
Last synced: 5 months ago
JSON representation
Python regular expression file transformer
- Host: GitHub
- URL: https://github.com/malthejorgensen/repx
- Owner: malthejorgensen
- License: bsd-2-clause
- Created: 2017-02-16T21:30:26.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2025-08-24T21:08:36.000Z (10 months ago)
- Last Synced: 2025-08-25T00:38:46.421Z (10 months ago)
- Topics: command-line-tool, data-analysis, text-processing
- Language: Python
- Size: 16.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
repx
====
Python regular expression file transformer.
If you know `sed` or `awk` – or even `vim`'s search & replace functionality,
`repx` should feel familiar, but simpler and easier to use.
`repx` is similar to [sd](https://github.com/chmln/sd).
Usage
-----
By default `repx` will take input from _standard in_ and output the transformed text to _standard out_
```ShellSession
$ echo 'Hello World!' | repx /World/Universe/
Hello Universe!
```
File input is of course also supported
```ShellSession
$ cat in.txt
I like command line tools!
$ repx /like/love/ in.txt
I love command line tools!
```
Files can be transformed in-place with `-i`/`--in-place`
```ShellSession
$ cat in2.txt
I like turtles!
$ repx -i /like/love/ in.txt int2.txt
$ cat in.txt
I love command line tools!
$ cat in2.txt
I love turtles!
```
Backreferences are supported both for normal search and during
substitution, but backslash escapes on the command line can be tricky,
so it can be helpful to use `\g<1>` in place of `\1`:
```ShellSession
$ repx -i '/YAML(Reader|Writer)/JSON\1/' [files...] # Won't work
$ repx -i '/YAML(Reader|Writer)/JSON\g<1>/' [files...] # Will work
```
Typical use
-----------
Typical use is within a git repository and the `-i` option.
`-i` will irreversibly change the files passed on the command line so
be sure to commit previous changes before running the command.
Usually you will use `repx` in tandem with `git grep -l` like
so:
```ShellSession
$ repx -i /YAMLReader/JSONReader/ $(git grep -l YAML)
# All files in the git repository containing "YAML"
```