replace 'var' 'let' *
sed -ri 's,var,let,g' *
replace 'var' 'let' . -r
find . -type f -print0 | xargs -0 sed -ri 's,var,let,g'
replace 'var' 'let' test/file1.js test/file2.js
sed -ri 's,var,let,g' test/file1.js test/file2.js
replace '(\w+)_(\w+)' '$1-$2' *
sed -ri 's,(\w+)_(\w+),\1-\2,g' *
replace 'var' 'let' . -r --include="*.js"
find . -type f -name '*.js' -print0 | xargs -0 sed -ri 's,var,let,g'
replace 'var' 'let' . -r --exclude="*.min.js,*.py"
find . -type f ! -name '*.min.js' ! -name '*.py' -print0 | xargs -0 sed -ri 's,var,let,g'
replace 'var' 'let' . -r --preview
find . -type f -exec sh -c "echo == {}; sed -r 's,var,let,g' {}" \;
(not sure if --preview does exactly that, I echo the filename followed by the modified content)
There is only one case that justifies reimplementing things: if your tool has the requirement of supporting the exact js regex syntax, then yes you did the right thing to reimplement this in js. I have run into similar situations myself. One time I had to support Perl regexs, and I started by simply using Python's standard regex module, thinking that it would work because both Perl and Python use PCRE. Well as it turned out the regexs I encountered used some advanced features (such as negative/postive look-behind/look-ahead, etc) that Python's regex module plainly did not suppport. So I ended up rewriting part of my implementation in Perl.Edit: I spoke too fast. As a commenter pointed out, other legitimate cases for reimplementing this in js would be when you can't afford to or don't want to fork a process to run find/xargs/sed. It sounds like you were running the tool from the command line, so I didn't think that would be your situation.
Edit 2: Yes, the exercise of reinventing the wheel is also useful for learning... I am not going to argue that.
Edit 3: If you care about simplicity, I would personally rather write a small shell script wrapping find/xargs/sed and hiding their arcane options, as opposed to writing 173 lines of js.