I needed sed today on Windows, and though there are versions of it available, or cygwin would work, I don't have privileges to install software on my client's machine.
Well, at least I had groovy. So I did this:
new File(args[0]).eachLine { line -> println(line.replaceAll(args[1], args[2])) }
And in a .bat file, this:
echo off IF /i "%1" == "/?" ( echo [path expression] [match regex] [replace string] [output dir] ) ELSE ( for %%f in (%1) DO (echo converting "%%f" to "%4\%%~nxf") && (groovy replaceAll.groovy "%%f" "%2" %3) > "%4\%%~nxf" )
Yeah, I could have done the entire thing in groovy, but I've never used 'for' in cmd.exe before, and I just wanted to try it.
I'll probably not do it again, unless I have no other choice. Anyway, it's here for future reference in case I ever have to use it again.
No comments:
Post a Comment