• This repository has been archived on 26/Sep/2023
  • Stars
    star
    748
  • Rank 60,661 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 13 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Command line search and replace utility

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

More Repositories

1

brain

Simple feed-forward neural network in JavaScript
JavaScript
8,006
star
2

kittydar

Face detection for cats in JavaScript - demo for TXJS 2012 talk
JavaScript
1,419
star
3

classifier

Bayesian classifier with Redis backend
JavaScript
625
star
4

clustering

K-means and hierarchical clustering
JavaScript
498
star
5

nomnom

Option parser for node with generated usage and commands
JavaScript
470
star
6

hog-descriptor

[UNMAINTAINED] Histogram of Oriented Gradients (HOG) descriptor extractor
JavaScript
169
star
7

glossary

[UNMAINTAINED] Extract terms and keywords from a piece of text
JavaScript
168
star
8

fxconsole

[UNMAINTAINED] Remote JavaScript console for Firefox
JavaScript
127
star
9

firefox-client

[UNMAINTAINED] Node.js remote debugging client for Firefox
JavaScript
100
star
10

costco

UI for bulk editing CouchDB docs
JavaScript
56
star
11

js-select

[UNMAINTAINED] Traverse and modify objects using JSONSelect selectors
JavaScript
56
star
12

rainbow

Color tools for Firefox
JavaScript
39
star
13

txjs-slides

dzslides deck for my txjs talk
CSS
14
star
14

mac-sounds

Play default OS X sounds from node
JavaScript
9
star
15

bzhome

Bugzilla dashboard
JavaScript
8
star
16

passion-project-slides

Slides for my Passion Projects talk on Machine Learning and JS
JavaScript
7
star
17

tcm

Mozilla's new testcase manager
JavaScript
5
star
18

detect-indent

CSS
5
star
19

searchbugs

Search for Bugzilla bugs by component
JavaScript
4
star
20

test-pages

Testcase websites for devtools
JavaScript
3
star
21

devtools-guide

3
star
22

showsearch

Jetpack that shows search terms in Firefox's awesomebar
JavaScript
3
star
23

firefontfamily

A Firebug extension that highlights the rendered font-family
JavaScript
2
star
24

contextfont

Firefox addon to find fonts on websites
JavaScript
2
star
25

celestial-snips-app

Snips voice assistant that answers celestial questions
Python
2
star
26

mini-devtools

mini in-content devtools
JavaScript
2
star
27

artfulimage

The Artful Image fine printing
2
star
28

bztweaks

mirror of Bugzilla Tweaks Firefox addon (https://bitbucket.org/ehsan/bugzilla-tweaks)
JavaScript
2
star
29

fluent-talk

JavaScript
1
star
30

bugidhelper

Bugzilla bug id linkifier and tooltipifier extension
JavaScript
1
star
31

brooklynjs-slides

Write your own in-content devtools with web APIs
CSS
1
star
32

test-snips-calc

Test Snips Calc Action
Python
1
star
33

harth

harth's no.de code
1
star
34

wwcode

A small website for Women Who Code SF
JavaScript
1
star
35

celestial-jupyter

Jupyter Notebook
1
star
36

test.js

Whatever's in my ~/test.js
JavaScript
1
star