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 world→goodbye world - lowercase and separated by underscores (snake_case):
hello_world→goodbye_world - uppercase and separated by underscores (SCREAMING_SNAKE_CASE):
HELLO_WORLD→GOODBYE_WORLD - lowercase and separated by hyphens (kebab-case):
hello-world→goodbye-world - separated only by capitalizing the first letter of each word (CamelCase):
HelloWorld→GoodbyeWorld - separated only by capitalizing the first letter of each word except the first
(lowerCamelCase):
helloWorld→goodbyeWorld
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):
- abolish.vim (can do this and other loosely related things)
- SmartCase
- keepcase.vim
Metadata
Release files for cawspr 0.1.2
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 |
|---|---|---|---|---|
| cawspr-0.1.2.tar.gz | 4.1 kB | Without provenance | Details for cawspr-0.1.2.tar.gz |
Release files / cawspr-0.1.2.tar.gz
| Download URL | cawspr-0.1.2.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4e90fb1c5fb1d4da9929e5f211b879641d2281ed4244a7e83a636637b6b156f
|
|
BLAKE2b-256 checksum How to use checksums |
11e2ef3fc860d1ab818b69cad6d4f7487cd9c180db72b9d0eec2b84c0dba522f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Security for cawspr 0.1.2
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.