You are previewing grep Pocket Reference.

grep Pocket Reference

Cover of grep Pocket Reference by John Bambenek... Published by O'Reilly Media, Inc.
O'Reilly logo

Choosing Between grep Types and Performance Considerations

Now that we have gone over all four grep programs, the question is how should you determine which to employ for a given task. For most routine uses, people tend to use the standard grep command (grep -G) because performance isn’t an issue when searching small files and when complex search patterns aren’t necessary. Generally, the basic grep is the default choice for most people, and so the question becomes when it makes sense to use something else.

When to Use grep -E

Although almost everything can be done in grep -G that can be done in grep -E, the latter has the advantage of accomplishing the task in fewer characters, without the counterintuitive escaping discussed earlier. All of the extra functionality in extended regular expressions has to do with quantifiers or subpatterns. Additionally, if any significant use of backreferences is needed, extended regular expressions are ideal.

When to Use grep -F

There is one prerequisite to using grep -F, and if a user cannot meet that requirement, grep -F is simply not an option. Namely, any search pattern for grep -F cannot contain any metacharacters, escapes, wildcards, or alternations. Its performance is faster, but at the expense of functionality.

That said, grep -F is extremely useful for quickly searching large amounts of data for tightly defined strings, making it the ideal tool to search through immense logfiles quickly. In fact, it is fairly easy to develop a robust “log watching” ...

The best content for your career. Discover unlimited learning on demand for around $1/day.