Skip to main content

Case and word separation preserving replace

Project description

cawspr

Case And Word Separation Preserving Replace (CAWSPR)

What does this do?

This script is as simple as it is stupid: You give it a list of words to replace (e.g. hello world) and a list of words to replace them with (e.g. goodbye world) and it will perform this replacement for various compositions of these words that are common e.g. in programming:

  • separated by spaces: hello worldgoodbye world
  • lowercase and separated by underscores (snake_case): hello_worldgoodbye_world
  • uppercase and separated by underscores (SCREAMING_SNAKE_CASE): HELLO_WORLDGOODBYE_WORLD
  • lowercase and separated by hyphens (kebab-case): hello-worldgoodbye-world
  • separated only by capitalizing the first letter of each word (CamelCase): HelloWorldGoodbyeWorld
  • separated only by capitalizing the first letter of each word except the first (lowerCamelCase): helloWorldgoodbyeWorld

The text in which to make these replacements must be piped into the script's standard input and it will output the resulting modified text to standard output.

That's it.

Installation

pip3 install cawspr

Usage

Replacing all occurrences of hello world and its variants in a file original.txt with goodbye world and writing the result to replaced.txt:

cat original.txt | cawspr 'hello world' 'goodbye world' > replaced.txt

Advertisement

Want to perform such replacements for both file contents and file paths in a directory recursively? Consider full-apply which works great with cawspr!

Similar projects and other resources

  • Softwarerecs StackExchange question in which I asked if anyone knows of an existing CLI tool that does this (perhaps more will crop up in the future)
  • The answers to [this StackOverflow question] are full of links to vim plugins for the same purpose (but I wanted it as a CLI tool):

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

cawspr-0.1.2.tar.gz (4.1 kB view hashes)

Uploaded Source

Supported by

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