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.4.1.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

apply_subs-0.4.1-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file apply_subs-0.4.1.tar.gz.

File metadata

  • Download URL: apply_subs-0.4.1.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for apply_subs-0.4.1.tar.gz
Algorithm Hash digest
SHA256 b4d943e801cac29fcdcff725d51282f0f7565744948507ef640936601b193613
MD5 4147a3e176ba7d12b5768ce637b90b71
BLAKE2b-256 5b1accb34f98d51f25c2224423c2c8ad7b438af1ef7b87719a90ca101337cee3

See more details on using hashes here.

File details

Details for the file apply_subs-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: apply_subs-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for apply_subs-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3be1fdcd92c1289abe1acf9119ef8c87265c38ffb03a40ae3ce765cf72577fc0
MD5 5e84e0053d87ac94cb9bbd44cf866af9
BLAKE2b-256 93796ab52104acddf4aa61ed42d273a13bba9558971016a2caa6be023cefe25a

See more details on using hashes here.

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