|
July 2004
Tool of the Month: rpl
This month, I'll introduce a tool that is handy for admins, programmers, and anybody who works with text files on a regular basis. The utility is rpl, short for "replace strings", which is exactly what it does. rpl is a simple utility that searches files for a text string and replaces that text string with another that you specify.
Replace Strings with rpl
It's possible to replace text strings in multiple files with numerous *nix utilities, but that involves getting to know a programming language or the arcane syntax of sed, awk, or some other program. While I'm a big fan of sed and Perl, for example, there's also something to be said for a utility that allows users to become productive in a matter of minutes rather than learning a programming language.
That's where rpl comes in. Is it as powerful as sed or Perl? Nope. But it is a quick and easy way to make changes in text files and it shouldn't take more than a few minutes to learn.
The basic syntax of rpl is rpl 'oldtext' 'newtext' filename. It doesn't really get much simpler than that, now does it? Note that strings should be placed inside single quotes (') so that the shell doesn't try to treat part of your text string as a special character. If you're replacing a single word with another single word (in other words, no white space) then it's not mandatory to place your strings inside single quotes but it's a good habit to get into.
There are also several options that may be of interest when using rpl. Let's say you want to replace all instances of the string "Copyright 2003-2004" with "Copyright 2003-2005" in all files with the extensions ".p
|