apply-subs
A command line application to apply a dictionnary (json) of substitutions to text file corpus. This program is a find-and-replace tool to perform a arbitrarily large set of substitutions in a reproducible fashion.
Disclaimer, this app is far less powerful than sed and in particular doesn't
support regex replacement. What it offers a simpler interface to make simple
sweeping changes across a whole project in a reproducible fashion.
Installation
The easiest installation method is
$ pip install apply-subs
In order to install apply-subs in isolation, use pipx instead.
Examples
apply-subs uses a json file as input. This file should specify substitutions
as new: old, where old can either be a single str, or a list of strings.
minimal case
echo "bunnies and bongos and bananas" > mytext.txt
echo '{"bunnies": "rabbits", "SECRETS": ["bongos", "bananas"]}' > mysubs.json
apply-subs mytext.txt -s mysubs.json
will print the patched content
bunnies and SECRETS and SECRETS
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
Metadata
Release files for apply-subs 0.5.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| apply_subs-0.5.5.tar.gz | 16.7 kB | Without provenance | Details for apply_subs-0.5.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apply_subs-0.5.5-py3-none-any.whl | Python 3 | none | any | Details for apply_subs-0.5.5-py3-none-any.whl |
Total release size: 33.5 kB
Release files / apply_subs-0.5.5.tar.gz
| Download URL | apply_subs-0.5.5.tar.gz |
|---|---|
| Size | 16.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5dc5c0442eec945ff34f76dd044d83d4afd442fdc70f87a204280fc793db9a6f
|
|
BLAKE2b-256 checksum How to use checksums |
83ea6e0df80e74a60e65c8b5ace51b01e2e49482f02c63ebbb5404e17278cb8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / apply_subs-0.5.5-py3-none-any.whl
| Download URL | apply_subs-0.5.5-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9ad46e1bb208878b4b252d1f1048a062ea588dfaa88b58e1394e96681367bd0c
|
|
BLAKE2b-256 checksum How to use checksums |
70e9d5835110b2cf7d175a9ec5ca9dc5001f2c0cc6ef2916337e714e1215825e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for apply-subs 0.5.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.