1.2.2 • Published 2 years ago

replace v1.2.2

Weekly downloads
144,203
License
MIT
Repository
github
Last release
2 years ago

COMMON ISSUE ON WINDOWS

There is a built-in replace command on windows, if you get an error like this

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:

Install

With node.js and 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:

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

vijaybabu-editblue-bar-plugin@bhws/source-craft-graphqlvijaybabusampleeditorwebapp-clirequesthorblue-bar-projectnestjs-create-modulecreate-sparkle@tomcarman/raven@ketcher/reactg3d-backend-automationssh-manager-cli-test@ionic/e2einspira-clirtwister@67p/aragon-cli@swiftbriefapp/cli@ali_znzd/generate-react-cli@infinitebrahmanuniverse/nolb-replneotw@everything-registry/sub-chunk-2651@ayyo/react-clinextpayne_clicordova-plugin-accountkitcopy-replacecometjscoldframe-clicockatricecoffee2jsoncloudforgecobaltianscreate-my-boiler-platecreate-react-wpcreate-wordpress-plugincreate-tableau-extensioncreate-sparkle-learningcreate-spring-boot-appcordova-set-version-namecreate-foundry-projectcrafty-clicreate-aragon-appcreate-hyper-mendix-widgetcreate-express-ts-servercreate-gl-occreate-emptycrashboomcreate-jqwidgets-angular-appcreate-jqwidgets-react-appcreate-jqwidgets-react-tsx-appcreate-jqwidgets-vue-appcreate-microfrontend-appcreate-microfrontend-shell-appcreate-mntm-vkmacreate-react-monorepo-appcreate-mendix-widgetdami-procreatorcreek-themesdatart-fe-clicssimporterisl-crm-clierisl-nsgmencyte-backendensokickstartember-cli-icomoonexpress-api-jwt-authexpress-mvc-builderetaffacily-cordova-plugin-accountkitficklebeans-create-adminficklebeans-create-modelfeiyu-clifflutterfeastjseasyv-scriptsfrom-rootfaccin_machinedataviewer_bridgefliflint-betaflexjsflintfliplet-clifluentui-svg-icon-spritesgulp-checkstyle-jenkins-reportergrunt-sedgrunt-colors-to-less-operationsgrunt-ngsrcgrunt-kairekaigrunt-debian-packagegrunt-static-versioning-requirejsgulp-protectgenerator-symfony-vagrantgenerator-seng-modulegenerator-reactiveuigenerator-oddgenerate-react-cligenerate-react-redux-cligenerate-solidjs-cligenerate-vue-cligenerator-moxie-lean
1.2.2

2 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.3.0

10 years ago

0.2.10

10 years ago

0.2.9

11 years ago

0.2.8

11 years ago

0.2.7

11 years ago

0.2.6

11 years ago

0.2.5

11 years ago

0.2.4

12 years ago

0.2.3

12 years ago

0.2.2

12 years ago

0.2.1

12 years ago

0.2.0

12 years ago

0.1.11

12 years ago

0.1.10

12 years ago

0.1.9

13 years ago

0.1.8

13 years ago

0.1.7

13 years ago

0.1.6

13 years ago

0.1.4

13 years ago

0.1.3

13 years ago

0.1.1

13 years ago

0.1.0

13 years ago