Skip to main content

A command line tool to apply substitutions to a text file

Project description

apply-subs

PyPI codecov pre-commit.ci status Imports: isort Code style: black

Apply a dictionnary (json) of substitutions to a text file.

Installing

$ pip install apply-subs

Examples

minimal

$ echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit" > mytext.txt
$ echo '{"Hello": "Lorem ipsum", "goodbye": "adipiscing elit"}' > mysubs.json
$ apply-subs mytext.txt mysubs.json

will print the patched content

Hello dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore goodbye.

patch mode

In patch mode (-p/--patch), print a patch diff instead of the end result

--- mytext.txt
+++ mytext.txt (patched)
@@ -1 +1 @@
-Lorem ipsum dolor sit amet, consectetur adipiscing elit
+Hello dolor sit amet, consectetur goodbye

Use -cp/--cpatch/--colored-patch for a colored output (when supported).

inplace substitutions

-i/--inplace

apply-subs --inplace mytext.txt mysubs.json

is equivalent to

apply-subs mytext.txt mysubs.json > mytext.txt

Project details


Download files

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

Source Distribution

apply_subs-0.2.0.tar.gz (16.2 kB view hashes)

Uploaded Source

Built Distribution

apply_subs-0.2.0-py3-none-any.whl (16.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page