Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apply-subs

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apply-subs

A command line tool to apply substitutions to a text file

  • 0.5.5
  • PyPI
  • Socket score

Maintainers
1

apply-subs

PyPI PyPI codecov pre-commit.ci status Imports: isort Code style: black

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc