Skip to content
/ regexec Public

A simple tool to replace text in file streams based on replacing a regex match by the output of a command being run with the match groups as arguments.

License

Notifications You must be signed in to change notification settings

fps/regexec

Repository files navigation

regexec

Note: Even though the tool expects input from stdin it consumes the whole input before starting to process because regexes :)

Note: With default parameters it replaces [include somefile.txt] by the contents of somefile.txt. See the example below.

Usage

README.md was generated from README.md.in via:

cat README.md.in | ./regexec -e "\[usage\]" -c "./regexec -h" -n 1 > README.md

This way you get this:

usage: regexec [-h] [-e E] [-n N] [-c C] [-v V]

optional arguments:
  -h, --help  show this help message and exit
  -e E        The (python2) regular expression (default: \[include (.+?)\])
  -n N        How many characters to strip from the end of command outputs -
              useful to remove trailing newlines (default: 0)
  -c C        The command to run with the expression's match groups as
              arguments and who's output replaces the match (default: cat \1)
  -v V        The verbosity level (default: 0)

Example - Including Textfiles into a Textfile

Given text1.txt:

Lalala

and text2.txt:

Lululu

and text3.txt:

This text should go

[include text1.txt]

and then

[include text2.txt]

this:

cat text3.txt | regexec -n 1

should give:

This text should go

Lalala

and then

Lululu

Example - Doing Math in a Textfile

This:

echo "Yo, 1 + 2 = [bc 1 + 2]. But 4 - 3 = [bc 4 - 3]" | regexec -e "\[bc (.*?)\]" -c "echo  \1  | bc"  -n 1

should give

Yo, 1 + 2 = 3. But 4 - 3 = 1.

About

A simple tool to replace text in file streams based on replacing a regex match by the output of a command being run with the match groups as arguments.

Resources

License

Stars

Watchers

Forks

Packages

No packages published