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.
By default repx will take input from standard in and output the transformed text to standard out
$ echo 'Hello World!' | repx /World/Universe/
Hello Universe!File input is of course also supported
$ 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
$ 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:
$ repx -i '/YAML(Reader|Writer)/JSON\1/' [files...] # Won't work
$ repx -i '/YAML(Reader|Writer)/JSON\g<1>/' [files...] # Will workTypical 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:
$ repx -i /YAMLReader/JSONReader/ $(git grep -l YAML)
# All files in the git repository containing "YAML"