Unix Review > Archives > 2004 > July 2004

July 2004

Tool of the Month: rpl

by Joe "Zonker" Brockmeier

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

Sys Admin Spotlight

CMP DevNet Spotlight

Ada and the Language Renaissance
A renaissance in computer language design has allowed "little" languages like Ruby and Lisp to accumulate large, active communities of developers that continue to discover new uses for these technologies. Ada is another language that has benefitted from grassroots-level development. The result: Ada 2005.

In the News

CD-ROM

Sys Admin and The Perl Journal CD-ROM version 11.0

Version 11.0 delivers every issue of Sys Admin from 1992 through 2005 and every issue of The Perl Journal from 1996-2002 in one convenient CD-ROM!

Order now!




MarketPlace

�Six Sigma� Certified?
100% Online-Six Sigma Certificate From Villanova -Find Out More Now.

Project Management-Online
Nation's Leading Online PMP Course From Villanova-Find Out More Now.

Automate Software Builds with Visual Build Pro
Easily create an automated, repeatable process for building and deploying software.

WinDev 12 - Powerful IDE
Develop 10 times faster ! ALM, IDE, .Net, RAD, 5GL, Database, 5GL, 64-bit, etc. Free Express version

Wanna see your ad here?