FART: easy grep-like utility for Windows

The Find And Replace Text utility is a handy little command-line tool to have if you're a Windows user. It can function as a simple grep-like utility for quickly searching through whole directories of files, and you can also use it to perform mass search and replace operations on a file or group of files.

The command format is fart <options> filename search <replace>. Basic options are -r (recursive), -c (print filename and match count), -i (ignore case), -n (print matched line numbers), --c-style (interpret backslashes as c-style characters).

For example, let's say a Linux buddy of yours sent you a bunch of html files and they have unix line endings that are barfing in notepad. One simple command fixes the problem, replacing all the newlines with a full PC carriage return, line feed combo:

fart --c-style *.html \n \r\n

Or perhaps you need to quickly track down some work that is left to be done throughout a big project directory. You can use fart to recursively search a directory and spit out all the file names and line numbers containing the text "TODO":

fart -nr * TODO

It's easy to see how you could shoot yourself in the foot with this one. Make sure to fart with caution and back up your files before doing a big search and replace.

FART @ SourceForge - Link

Posted by Jason Striegel | Feb 7, 2008 09:55 PM
Lifehacker, Windows | Permalink | Comments (5) Bookmark and Share

Recent Entries

Comments

Newest comments listed first.

Posted by: Mihai Criveti on February 8, 2008 at 9:18 AM

Try "findstr", it does Regular Expressions. Part of Windows too :-).

C:\Windows\System32\findstr.exe -?
[..]

Regular expression quick reference:
. Wildcard: any character
* Repeat: zero or more occurrences of previous character or class
^ Line position: beginning of line
$ Line position: end of line
[class] Character class: any one character in set
[^class] Inverse class: any one character not in set
[x-y] Range: any characters within the specified range
\x Escape: literal use of metacharacter x
\ Word position: end of word


Posted by: Andy Lester on February 9, 2008 at 8:37 AM

ack is also a good choice for Windows. It's pure Perl, uses Perl regular expressions, and is well-supported.

http://petdance.com/ack/


Posted by: How does this compare to mtr? on February 11, 2008 at 10:21 AM

How does this program differ from MiniTrue? http://www.student.northpark.edu/pemente/sed/minitrue.htm


Posted by: Mahmudul Hasan on February 11, 2008 at 7:25 PM

Fart is cool.

Findstr is a powerfull tool i know. But fart is very handy for certain jobs, for which findstr will take a lengthier command.

Mahmudul Hasan


Posted by: TomasV on March 7, 2008 at 2:45 PM

This looks like a nice tool, but a RegEx search and REPLACE command-line utility would be nice (which the above mentioned aren't). Is there even any (for Windows)? It's planned for FART based on the info on th SF.net page.


Leave a comment



Bloggers

Welcome to the Hacks Blog!

Brian Jepson.Brian Jepson


Jason Striegel.Jason Striegel


Philip Torrone.Phillip Torrone



See all of the books in the Hacks Series!
Advertise here.

Recent Posts

www.flickr.com
photos in Hacks More photos in Hacks

Most read entries (last 30 days)