From the course: Bash Patterns and Regular Expressions
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Using regular expressions with grep - Bash Tutorial
From the course: Bash Patterns and Regular Expressions
Using regular expressions with grep
- [Instructor] Grep may be the most common tool in Linux to use regular expressions with. In fact, the name grep stands for global regular expression print. Let's talk about some grep options that deal with regular expressions. By default, grep uses BREs, but it supports EREs if you pass the -E option, or you use the egrep command. The egrep command name has been deprecated, but is kept around for historical reasons, as some tools still rely on that name existing. We're going to focus on using EREs with grep in this video. If you're not using GNU Grep, then you may not have access to back-references and EREs, so be aware, you may have to convert these examples to BREs for your version of grep. If you want to force grep to process a regex as a BRE, you can pass the -G option. Perhaps the only way of using Perl-compatible regular expressions in bash is to pass the -P option to grep. This is experimental, and not all features are supported. Normally, the expression is assumed based on…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.