Using Perl to Replace or Delete Strings

Perl is a complete programming language that runs under both UNIX and Windows. Although it usually does not come packaged with any commercial UNIX distribution, it is readily available via the Internet for most UNIX systems. If Perl is available on your system, you can also use it as a simple command-line utility that provides replacement capabilities not available in sed.

For simple replacement, perl is just like sed if you use the –pe option to perl. The following two commands are equivalent:

     sed 's/Mr. Smith/Ms. Wilson/g' report7
perl -pe 's/Mr. Smith/Ms. Wilson/g' report7

Earlier, this chapter discussed the g flag for sed. It means the same thing to perl: process all patterns on the line, not just ...

Get Practical UNIX now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.