Skip to main content

A command line tool to apply substitutions to a text file

Project description

apply-subs

GitHub tag (latest by date) 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.2.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apply_subs-0.1.2-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: apply_subs-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 4477b37978f61e236586e17e58eeebfcef873d7d3fbdb642e0b9519c375f8f4a
MD5 4b7c40e0d853f1501f1d2b996598bca2
BLAKE2b-256 5d68443e4e213fc234febd73e8c85fecdc27d31d88b50ef5411b094b786bc37e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: apply_subs-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.3 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3b08f756bec3b0cc211611cdc0b8f223485e4d29f02bd8aa3dad29f13640f4e1
MD5 e977846ccd821a0a61afa54422662aff
BLAKE2b-256 e0a962931eb359758de9461286e45106ff987f5f6a4d19955f7f4cd82c0ff12b

See more details on using hashes here.

Supported by

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