# replace

> Command line search and replace utility

Latest version **1.2.2** (published 2022-10-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install replace
pnpm add replace
yarn add replace
bun add replace
```

Provides the commands `search`, `replace`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2022-10-25 |
| First published | 2011-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 6 |
| Dependencies | 3 |
| Unpacked size | 23 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 62 |
| Author | Alessandro Maclaine |
| Maintainers | almaclaine |
| Keywords | sed, grep, search, replace |

## Links

- npm: https://www.npmjs.com/package/replace
- Repository: https://github.com/ALMaclaine/replace
- Homepage: https://github.com/ALMaclaine/replace#readme
- Issues: https://github.com/ALMaclaine/replace/issues
- npm.io page: https://npm.io/package/replace

## Dependencies (3)

- [chalk](https://npm.io/package/chalk.md) 2.4.2
- [yargs](https://npm.io/package/yargs.md) ^15.3.1
- [minimatch](https://npm.io/package/minimatch.md) 3.0.5

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.2.2 (latest) — 2022-10-25
- 1.2.1 — 2021-03-27
- 1.2.0 — 2020-04-24
- 1.1.5 — 2020-01-09
- 1.1.4 — 2020-01-09
- 1.1.3 — 2020-01-01
- 1.1.2 — 2019-12-31
- 1.1.1 — 2019-08-20
- 1.1.0 — 2019-03-02
- 1.0.1 — 2018-12-17
- 1.0.0 — 2018-05-08
- 0.3.0 — 2014-09-09
- 0.2.10 — 2014-09-09
- 0.2.9 — 2014-01-23
- 0.2.8 — 2014-01-21
- … 18 more at https://npm.io/package/replace/versions

## README

# COMMON ISSUE ON WINDOWS
There is a built-in replace command on windows, if you get an error like this

```shell
Invalid switch - -h
No files replaced
```

You are using the windows replace

# replace
`replace` is a command line utility for performing search-and-replace on files. It's similar to sed but there are a few differences:

* Modifies files when matches are found
* Recursive search on directories with -r
* Uses [JavaScript syntax](https://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions#Using_Simple_Patterns) for regular expressions and [replacement strings](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter).

# Install
With [node.js](http://nodejs.org/) and [npm](http://github.com/isaacs/npm):

	npm install replace -g

You can now use `replace` and `search` from the command line.


## Examples

Replace all occurrences of "foo" with "bar" in files in the current directory:

```
replace 'foo' 'bar' *
```

Replace in all files in a recursive search of the current directory:

```
replace 'foo' 'bar' . -r
```

Replace only in test/file1.js and test/file2.js:

```
replace 'foo' 'bar' test/file1.js test/file2.js
```

Replace all word pairs with "_" in middle with a "-":

```
replace '(\w+)_(\w+)' '$1-$2' *
```

Replace only in files with names matching *.js:

```
replace 'foo' 'bar' . -r --include="*.js"
```

Don't replace in files with names matching *.min.js and *.py:

```
replace 'foo' 'bar' . -r --exclude="*.min.js,*.py"
```

Preview the replacements without modifying any files:

```
replace 'foo' 'bar' . -r --preview
```

Replace using stdin:

```
echo "asd" | replace "asd" "dsa" -z
```

See all the options:

```
replace -h
```

## Search
There's also a `search` command. It's like `grep`, but with `replace`'s syntax.

```
search "setTimeout" . -r
```

## Programmatic Usage
You can use replace from your JS program:

```javascript
var replace = require("replace");

replace({
  regex: "foo",
  replacement: "bar",
  paths: ['./Test/'],
  recursive: false,
  silent: false,
});
```

## More Details

### Excludes
By default, `replace` and `search` will exclude files (binaries, images, etc) that match patterns in the `"defaultignore"` located in this directory.

### On huge directories
If `replace` is taking too long on a large directory, try turning on the quiet flag with `-q`, only including the necessary file types with `--include` or limiting the lines shown in a preview with `-n`.


## What it looks like
![replace](http://i.imgur.com/qmJjS.png)

---
_Source: https://npm.io/package/replace · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
