Chapter 3. Perl as a (better) grep command

3.1

A brief history of grep

53

3.2

Shortcomings of grep

54

3.3

Working with the matching operator

60

3.4

Understanding Perl’s regex notation

63

3.5

Perl as a better fgrep

64

3.6

Displaying the match only, using $&

64

3.7

Displaying unmatched records (like grep -v)

65

3.8

Displaying filenames only (like grep -l)

67

3.9

Using matching modifiers

68

3.10

Perl as a better egrep

70

3.11

Matching in context

75

3.12

Spanning lines with regexes

77

3.13

Additional examples

81

3.14

Summary

86

This chapter shows you how to write one-line Perl commands and small Perl scripts that surpass the limitations of the UNIX grep command. We’ll start by reviewing grep’s history, strengths, and weaknesses, and Perl’s superior features, and then we’ll show how Perl programs ...

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.