From the course: Bash Patterns and Regular Expressions

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Performance optimizing grep searches

Performance optimizing grep searches - Bash Tutorial

From the course: Bash Patterns and Regular Expressions

Start my 1-month free trial

Performance optimizing grep searches

- There can be a big difference in speed when using Grep depending on a few things. In Chapter one of this course, we talked about changing the locale setting to make sorting more consistent. There can be a large speed increase when the shell colation is set to a single bite locale such as C. Also, Grep is tuned to the C locale. When you're not using the C locale, character set ranges and colation equivalencies can be quite slow. Avoid them if possible. Backreferences can be slow, because that forces the search algorithm to backtrack through the data that's being processed. Case insensitivity is slow. Use a character set, listing the least amount of upper and lower case characters possible. Multiple simple searches can be faster than one complex search. Grep uses the Boyer-Moore fast string searching algorithm when matching a single fixed pattern, and the Aho-Corasick algorithm if used to match multiple fixed patterns. Matching one fixed pattern and piping it back into Grep and…

Contents