I'm looking to find / replace in alot of files and was wondering if anybody could recommend some good tools for Windows. I'd prefer them to be free.
Thanks
I'm looking to find / replace in alot of files and was wondering if anybody could recommend some good tools for Windows. I'd prefer them to be free.
Thanks
Install Cygwin, its free and gives a linux-like scriptable environment in Windows.
Do lookup the manual pages for commands I describe here (man find for example).
List files in a directory (folder) with,
find . -type f
## Note: you can also select files here (see the man page)
Use that to search in multiple files like this,
grep -Hn pattern $(find . -type f)
Use it to replace across files like this.
Create a script file (say) replace-in-files.sh
.
Write the following in the file,
#!/bin/sh
# Sample script: replace-in-files.sh
for f in $(<find . -type f);
do
sed 's/pattern/replacement/g' $f > tmpFile.txt
mv tmpFile.txt $f;
done;
rm -f tmpFile.txt
Here,
tmpFile.txt
should be some temporary name (not already existing in the directory).
And, pattern
is the regex you want to change with replacement
.
Execute chmod a+x replace-in-files.sh
and the file becomes an executable that you can fire from a Cygwin terminal with ./replace-in-files.sh
You can build up for there for many other requirements.
To lookup manual pages for commands like sed
, find
, grep
you can also google
"manual sed" etc.
The Advanced Bash Scripting guide at the Linux Documentation Project site is a good reference and most of the concepts work under Cygwin. Also has Awk, sed, briefs at the end.
Whilst probably not as fast as the above options - Notepad++ has a good find/replace with RegEx support.
I would go with Cygwin. If this is not desirable, on http://unxutils.sourceforge.net/ you can find a bunch of standalone GNU utilities like sed, grep and find ported to Windows.
I've been using Text WorkBench for a while now and think it's fantastic. It's got lots of useful features including batch replace plans, regular expressions, include/exclude file extensions, editing files inside the application, etc.
Not free though... Think it costs about $40, but is easily worth it given the amount of time it saves. I'm not affiliated with the company in anyway, just a happy customer.