Edit files in one pass with instructions via stdin
Project description
Newxt
⚠️ DISCLAIMER: This is a hobby/personal project. Not a commercial product. Not for production use.
Edit files in one pass with instructions via stdin
The replace command performs a simple string replacement on a file based on YAML instructions provided via stdin.
Quick installation (MacOS)
brew install pipx
pipx install newxt
Usage
newxt replace <file> < instructions.yaml
Or using a pipe:
echo "search: old\nreplace: new" | newxt replace myfile.txt
Arguments
file- Path to the file to perform replacement on (required)
Input Format
The command accepts YAML instructions via stdin with two required fields:
search- The text to search for in the filereplace- The text to replace it with
Simple Example
search: old_method
replace: new_method
Multiline Example
For multiline strings, use YAML's literal block scalar syntax:
search: |
def old_method():
print("old")
replace: |
def new_method():
print("new")
Behavior
- Only the first occurrence of the search string is replaced
- The file is not modified on disk - the result is returned to stdout
- The search is performed as an exact string match (not a regex)
- Both
searchandreplacevalues must be non-empty
Error Conditions
The command will raise an error if:
- The specified file does not exist
- The path points to a directory instead of a file
- No stdin is provided
- The stdin is not valid YAML
- The
searchfield is missing or blank - The
replacefield is missing or blank
Examples
Replace a function name
cat > instructions.yaml << EOF
search: calculate_total
replace: compute_sum
EOF
newxt replace mycode.py < instructions.yaml
Replace a multiline block
cat > instructions.yaml << EOF
search: |
if debug:
print("Debug mode")
replace: |
if self.debug:
self.logger.debug("Debug mode")
EOF
newxt replace app.py < instructions.yaml > app_updated.py
Using with pipes
echo "search: TODO\nreplace: DONE" | newxt replace notes.txt
Notes
- The command returns the modified content to stdout
- To save the result, redirect the output to a new file
- The original file remains unchanged
- Whitespace and indentation in the search string must match exactly
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file newxt-0.1.1.tar.gz.
File metadata
- Download URL: newxt-0.1.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e5b5f392d7a91105febbef08f7ab37bd8f493faf4bc6a52f86f5917910c5413
|
|
| MD5 |
7950d6668be16d9ca893df02dfb8277b
|
|
| BLAKE2b-256 |
a38be7f26eaf3a058d8a523d3cd284e3fdd7a715a581ee42af26123ac4e3c6d2
|
File details
Details for the file newxt-0.1.1-py3-none-any.whl.
File metadata
- Download URL: newxt-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0ae2b8a619bafabd96c3fff5453910c6fe1252bb534b5d242dfc03b70b5baa1
|
|
| MD5 |
23a7e4d0833772a282df318cbf239bd1
|
|
| BLAKE2b-256 |
df6dc325ad3bdc407bdd0f5715de5f51db3aa99d766f4fbf752b82c0369c0c8e
|