Windows Command Line Find and replace – Made easy

I finally found a great little application that does a find and replace on a particular file or file type, then replacing it with a string, of your choice. It also looks in sub directory, whilst there are many grep’s out there most are GUI for windows or pay for items that run command line… I like free better, don’t you?

And yes SED could do it, as could a few other apps, but why write something when this  can be done so much easier?

the small app is called FART, yes that’s right FART!

Here are the options FART provides

Find And Replace Text  v1.99b                         by Lionello Lunesu

Usage: FART [options] [--] <wildcard>[,...] [find_string] [replace_string]

Options:
-h, –help          Show this help message (ignores other options)
-q, –quiet         Suppress output to stdio / stderr
-V, –verbose       Show more information
-r, –recursive     Process sub-folders recursively
-c, –count         Only show filenames, match counts and totals
-i, –ignore-case   Case insensitive text comparison
-v, –invert        Print lines NOT containing the find string
-n, –line-number   Print line number before each line (1-based)
-w, –word          Match whole word (uses C syntax, like grep)
-f, –filename      Find (and replace) filename instead of contents
-B, –binary        Also search (and replace) in binary files (CAUTION)
-C, –c-style       Allow C-style extended characters (\xFF\t\n\r\\ etc.)
     –cvs           Skip cvs dirs; execute “cvs edit” before changing files
     –svn           Skip svn dirs
     –remove        Remove all occurences of the find_string
-a, –adapt         Adapt the case of replace_string to found string
-b, –backup        Make a backup of each changed file
-p, –preview       Do not change the files but print the changes

 

As an example

fart -c -r -i -p *.config databaseserver1 databaseserver2

this will look for all config files in a sub directory then looking for the databaseserver1 string within the .config file and then changing it to databaseserver2, If you notice i have a -p which means it wont actually change anything because this is a preview, showing you how many strings it found within each .config file.

Download FART here

http://sourceforge.net/projects/fart-it/


Leave a Reply