E-Mail:

Extending Grep

Extending grep

Early on in Penguin Shell, we spent some time talking about the myriad ways available in Linux to search for strings. grep was one of those tools. If you’ve been paying attention during the email filtering series, you’ve already seen that procmail uses an extended version of grep, egrep, to match strings for further processing. Specifically, egrep is executed from the ~/.procmailrc file to evaluate the headers and/or the bodies of your incoming mail.

Since egrep is an extension of grep, it’s useful to take a look at the grep man page to get a full understanding of what the foundation program does, as well as all its options. egrep adds to the grep expressions the characters +, ?, |, and (). These characters allow egrep to:

match one or more of the preceding character [+]
match zero or one of the preceding character [?]
match one expression or another [|]
group a series of expressions to match [()]

Here are some examples of egrep commands:

Command Matches
egrep ‘Victor(y)*’ file any instance of Victor or Victory in file
egrep ‘(Victor|Victory)’ file any instance of Victor or Victory in file (as above)
egrep ‘(nov|dec)*\.doc’ files all references to .doc files using ‘nov’ or ‘dec’ in files

As you’ve seen in the procmail series, some of the most productive uses of both grep and egrep are as tools for other programs. The output from these programs can be sent as the input to other programs to complete even the most complex task.

What Do You Think?

 

Want to Start a Blog Here for Free?

Are you an expert in one subject or another? If your goal is to help others and dispense hard-earned information back to the community, stake a claim on your very own Lockergnome blog today! You can write about anything - no matter the topic. Sign-up to start blogging!

64 queries / 0.343 seconds.