Chapter 4. Perl as a (better) sed command

4.1

A brief history of sed

89

4.2

Shortcomings of sed

91

4.3

Performing substitutions

93

4.4

Printing lines by number

100

4.5

Modifying templates

101

4.6

Converting special characters

103

4.7

Editing files

105

4.8

Converting to lowercase or uppercase

113

4.9

Substitutions with computed replacements

114

4.10

The sed to Perl translator

118

4.11

Summary

118

In this chapter, you’ll learn how to write Perl programs that surpass the limitations of the UNIX sed command. We’ll start by discussing the historical uses of sed, and then we’ll consider its modern-day applications—which are quite different.[1]

Then, we’ll explore a variety of commands and scripts that show how Perl can beat sed at its own game.

A brief history of sed

Although it isn’t ...

Get Minimal Perl now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.