Heather's Paragraphs

replace

I just published replace, a find-and-replace command line utility that others might find useful. I’m always wanting to replace strings spread throughout my code, and never found an easy way to do it. `find` + `sed` can do it, but the syntax is hard to remember and you don’t get easy-to-read feedback on what replacements are made. It’d be cooler if there were a tool devoted to this.

Replace takes a regular expression string (in JavaScript syntax), a replacement string, and files to search (or directories to search recursively when `-r` is specified). It will print out the lines that have been replaced:

There are quite a few other options and output choices, check out the GitHub for more information. It requires installing node.js and its package manager npm if you don’t already have them. Then you can install with:

npm install replace -g

Side note: It’s true that JavaScript is still quite a bit slower than bash/C, so it’s good to question why you’d write something like this in Javascript. I blame how nice it is to write programs in node, how nice it is to handle dependencies and distribute programs with npm, and all the really well-done node libraries out there (like colors for coloring console output). This is something I wouldn’t have taken my free time to write in any other environment.