A command line tool to apply substitutions to a text file
Project description
apply-subs
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
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
Built Distribution
File details
Details for the file apply_subs-0.4.2.tar.gz
.
File metadata
- Download URL: apply_subs-0.4.2.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfbdebe840e320b864e8a6686b66237bd85dbf359d8ebe03ed33dfdc72ecfc0c |
|
MD5 | c84360234b5b5e4dea5440416834c871 |
|
BLAKE2b-256 | dcaa4e0acb2cd158650d53d34a968c4d89cffbf7c039c889029ef8b9ab6ed2c5 |
File details
Details for the file apply_subs-0.4.2-py3-none-any.whl
.
File metadata
- Download URL: apply_subs-0.4.2-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ba4614719ad68192f0aea841fe0300d42f8ed5d5189719716e201377e9396f5 |
|
MD5 | d4fa6edfec7e05a1229c9c0831987915 |
|
BLAKE2b-256 | cdbde9ed09060469df4211944ec89433877157109662757097f004b3cc1e63ee |