Traverse a file tree and search/replace text in files mathing a search expression. Node.js command line utility.
- Download/git clone this repo
- Go to the folder
npm install
- Make sure it works
npm test
- Put the folder in your path
- (Write a convenience shell-script arund it)
node replace.js [-v -e <charEncoding> ] -i <fileMatchPattern> startDir searchPattern replaceString
-v Is optional. Enables verbose output.
-e charEncoding Is optional and defaults to utf8.
-i fileMatchPattern is required. Any file mathing the pattern will be searched and replaced into. Matching is done on the file name only (omitting path info).
startDir can be abslute or relative from the current working dir. replace.js will search the directory and recurse down all sub-directories.
searchPattern can be any valid javascript regexp. Internally, it is wrapped in a RegExp like this new RegExp(searchPattern, 'g')
.
Comment out all console.log()
node replace.js -v -i *js /home/user/projects/MyApp/src console "// console"
Note: Not really a safe thing to do, unless you know all of them are on separate lines!