Giter VIP home page Giter VIP logo

replace's Introduction

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

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: ['.'],
  recursive: true,
  silent: true,
});

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

replace's People

Contributors

bericp1 avatar danc86 avatar harthur avatar jeremyckahn avatar max-mapper avatar ncolgan avatar niftylettuce avatar panuhorsmalahti avatar pose avatar sc0ttkclark avatar sopo-to-iki avatar tmcw avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

theassyrian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.