A command line tool to apply substitutions to a text file
Project description
apply-subs
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
Release history Release notifications | RSS feed
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.1.tar.gz
(16.0 kB
view details)
Built Distribution
File details
Details for the file apply_subs-0.2.1.tar.gz
.
File metadata
- Download URL: apply_subs-0.2.1.tar.gz
- Upload date:
- Size: 16.0 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce218c54239e4a2419bb8a5a7cd9ae43e5d67e197340f040665593f492376262 |
|
MD5 | 026a94e92a668d25672799bdea2923e7 |
|
BLAKE2b-256 | 5147aff9191809c6eaa9ff61d736040e4842495cdfd44f0013797aee0c1b03f5 |
File details
Details for the file apply_subs-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: apply_subs-0.2.1-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 851d18e6134a5553cee9028285babdadb87f4f39bef9166f2d85bf2e760e61c3 |
|
MD5 | 6cdaebdd811ff731ff63441287a58657 |
|
BLAKE2b-256 | b40eb7e8a690d3744aa65d42d49e9e4283c564d97b4bd168edd0c09d6f9b5d50 |