https://github.com/svandriel/file-find-replace-cli
Command line tool for replacing text in files, using a JSON file containining matches and replacements
https://github.com/svandriel/file-find-replace-cli
cli file find replace
Last synced: 9 months ago
JSON representation
Command line tool for replacing text in files, using a JSON file containining matches and replacements
- Host: GitHub
- URL: https://github.com/svandriel/file-find-replace-cli
- Owner: svandriel
- License: mit
- Created: 2020-12-19T18:41:04.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-19T00:47:48.000Z (over 2 years ago)
- Last Synced: 2025-04-02T15:21:18.989Z (10 months ago)
- Topics: cli, file, find, replace
- Language: TypeScript
- Homepage:
- Size: 1.16 MB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.com/svandriel/file-find-replace-cli)
# file-find-replace-cli
Command-line tool to find and replace text in files.
## Installation
```
npm i -g file-find-replace-cli
```
## Usage
```bash
# Replace within a single file
find-replace replace.json -f 'data/users.txt'
# Or within multiple files (uses globs)
find-replace replace.json -f 'data/**/*.txt' -f 'src/**/*.ts'
```
## Syntax
```
$ file-replace -h
Usage: file-replace [options]
Command line tool for replacing text in files, using a JSON file containing matches and replacements.
The JSON file must contain an object (or array of objects), each containing a 'find' and 'replace' entry
Arguments:
replacementFile The JSON file containing matches and replacements
Options:
-V, --version output the version number
-f, --file [file...] Path or glob to a file to replace. Can be used
multiple times.
-v, --verbose Turns on verbose mode
-h, --help display help for command
```
## Replacement file
`replace.json` contains the replacement info:
```jsonc
[
{
"find": "foo",
"replace": "bar",
"ignoreCase": true // Optional
},
{
"find": "unicorn",
"replace": "🦄"
}
]
```
The file must contain a single replacement object, or an array of replacements.
```jsonc
{
"find": "",
"replace": "",
"ignoreCase": false, // optional; false by default
"wholeWord": false // optional; false by default
}
```