replace-x1.5.0 • Public • Published
replace-x is a command line utility for performing in place 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
npm install replace-x -g
You can now use
search-x from the command line.
Replace all occurrences of "foo" with "bar" in files in the current directory:
replace-x 'foo' 'bar' *
Replace in all files in a recursive search of the current directory:
replace-x 'foo' 'bar' . -r
Replace-x only in test/file1.js and test/file2.js:
replace-x 'foo' 'bar' test/file1.js test/file2.js
Replace-x all word pairs with "_" in middle with a "-":
replace-x '(\w+)_(\w+)' '$1-$2' *
Replace only in files with names matching *.js:
replace-x 'foo' 'bar' . -r --include="*.js"
Don't replace in files with names matching *.min.js and *.py:
replace-x 'foo' 'bar' . -r --exclude="*.min.js,*.py"
Preview the replacements without modifying any files:
replace-x 'foo' 'bar' . -r --preview
See all the options:
There's also a
search-x command. It's like
grep, but with
search-x "setTimeout" . -r
You can use replace from your JS program:
var replace = ;;
search-x will exclude files (binaries, images, etc) that match patterns in the
"defaultignore" located in this directory.
On huge directories
replace-x 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
### Line length
replace-x works on files with lines of 400 characters or less. If you need to work on long lines, gnu
sed supports unlimited line length.
### Symbolic links
replace-x does not traverse symbolic links for files in directories.
What it looks like