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

Uploaded Source

Built Distribution

apply_subs-0.1.3-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: apply_subs-0.1.3.tar.gz
  • Upload date:
  • Size: 16.1 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.1.3.tar.gz
Algorithm Hash digest
SHA256 60c781f07b303860bae4c73f400f7b2c9ec60d10372e485401a54a443ddd958f
MD5 516ffaf0de0512b084c98f138de83aff
BLAKE2b-256 e98934ba1565dbd4c5f173488fc6d91571780a14b927984fcd9000953320a180

See more details on using hashes here.

File details

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

File metadata

  • Download URL: apply_subs-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 16.2 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.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 645bdb8ad3c3fee7cb3910cf06f206a028b705fe5076d90b6ee4384765f86bf1
MD5 1e768db9870f5d2092b7c208d8673823
BLAKE2b-256 9aac30d49a35df290011c5d1bd234f45b5082d43970d25658433940e9634807b

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