Bash Patterns and Regular Expressions
2h 2mAdvanced2019-06-06
Authors

Grant McWilliams
Consultant, Speaker, Writer, Professor, Developer
Course details
Pattern matching allows you to create a script that can act on pieces of data if it matches a specific pattern. This makes it possible to script automation into a system process. In this course, learn how to use pattern matching in a Bash script using globs, extended globs, brace expansion, and regular expressions (regex). Throughout this course, Grant McWilliams covers the differences between basic and extended regexes and delves into using extended regexes in bash conditional statements, grep, sed, and AWK.
Learning objectives
What are globs and extended globs?
How locale affects searches
Making extended globs persistent
Comparing extended globs with regular expressions (regexes)
Using brace expansion for patterns
Working with extended regexes
Using sed
Regexes in AWK
Learning objectives
What are globs and extended globs?
How locale affects searches
Making extended globs persistent
Comparing extended globs with regular expressions (regexes)
Using brace expansion for patterns
Working with extended regexes
Using sed
Regexes in AWK
Skills covered
BashIT AutomationNetwork and System AdministrationOpen SourceDeep Dive (X:Y)
Concepts
Introduction
- Use Bash to pull data in seconds
- What you should know
Shell Globs
- What are globs
- Shell expansion order
- Wildcards
- Character sets
- The effect of locale on searches
- Character classes
- Shell globbing options
Shell Extended Globbing
- What are extended globs
- Why you should use extended globs
- Make extended globs persistent
- Getting started with extended globs
- Pattern matching with extended globs
- Using extended globs with commands
- Comparing extended globs with regular expressions
Shell Brace Expansion
- What is brace expansion
- Using brace expansion for patterns
Introduction to Regular Expressions
- What are regular expressions
- Why aren't regexes consistent
- Basic vs. Extended Regular Expressions
- Regex support in command line tools
- Matching characters and words
- Specifying occurrences
- Alternation and grouping
- Back references and subexpressions
Use Bash Extended Regexes
- Regexes in if conditionals
- Using BASH REMATCH
- Challenge - Regex to find credit card numbers
- Solution - Regex to find credit card numbers
Grep EREs and PCREs
- Using regular expressions with grep
- Perl compatible regexes with grep
- Performance optimizing grep searches
- Challenge - Create a regex to find telephone numbers
- Solution - Create a regex to find telephone numbers
Use sed Regexes
- Using sed
- Using extended regexes in sed
- Challenge - Create a regex to find IPv4 addresses
- Solution - Create a regex to find IPv4 addresses
Use AWK Extended Regexes
- Using regexes in AWK
- Pattern matching differences in AWK
Conclusion
- Next steps