27.10 Search RCS Files with rcsgrep
27.10.1 rcsgrep, rcsegrep, rcsfgrep
The rcsgrep script - and two links to it named rcsegrep and rcsfgrep -run grep , egrep (27.5 ) , and fgrep (27.6 ) on all files in the RCS directory. (You can also choose the files to search.)
The script tests its name to decide whether to act like grep , egrep , or fgrep . Then it checks out each file and pipes it to the version of grep you chose. The output looks just like grep 's - although, by default, you'll also see the messages from the co command (the -s option silences those messages).
By default, rcsgrep searches the latest revision of every file. With the -a option, rcsgrep will search all revisions of every file, from first to last. This is very handy when you're trying to see what was changed in a particular place - and to find which revision(s) have some text that was deleted some time ago. (rcsgrep uses rcsrevs (20.15 ) to implement -a .)
Some grep options need special handling to work right in the script: -e , -f , and -l . (For instance, -e and -f have an argument after them. The script has to pass both the option and its argument.) The script passes any other options you type to the grep command. Your grep versions may have some other options that need special handling, too. Just edit the script to handle them.
You can install this script from the CD-ROM or from the online archive (52.7 ) . If you get it from the archive, ask tar to install rcsgrep , its two other links rcsegrep and rcsfgrep , as well as rcsrevs .
To search an RCS file, rcsgrep and its cousins run several UNIX processes: co , grep , sed and others. Each process takes time to start and run. If your directory has hundreds of RCS files (like our directory for this book does), searching the whole thing can take a lot of time. I could have cut the number of processes by rewriting rcsgrep in Perl; Perl has the functionality of grep , sed and others built in, so all it would need to do is run hundreds of co processes...which would still make it too slow.
rcsegrep.fast is sort of a kludge because it's accessing RCS files without using RCS tools. There's a chance that it won't work on some versions of RCS, or that I've made some other programming goof. But it's worked very well for us. It's much faster than rcsgrep and friends. I'd recommend using rcsegrep.fast when you need to search the latest revisions of a lot of RCS files; otherwise, stick to the rcsgrep s.