Skip to main content

A command line tool to apply substitutions to a text file

Project description

apply-subs

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

A command line tool to apply a dictionnary (json) of substitutions to text files.

Installation

The easiest installation method is

$ pip install apply-subs

In order to install apply-sub in isolation, use pipx instead.

Examples

minimal case

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

will print the patched content

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

diff mode

Use diff mode (-d/--diff) to print a 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/--cdiff/--colored-diff for a colored output (when supported).

inplace substitutions

-i/--inplace

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

is equivalent to

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

target several files in one go

The target positional argument can consist of a single file (as illustrated above), or many. This is useful for instance if you need to apply a set of subtitutions to all files in a project whose name match a regexp.

$ git ls-files | egrep "(.md|.py)$" | xargs apply-subs -s subsubs.json -i

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.5.0.tar.gz (16.4 kB view hashes)

Uploaded Source

Built Distribution

apply_subs-0.5.0-py3-none-any.whl (16.6 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