0PricingLogin
Linux Command Line & Bash Scripting Mastery · Lesson

Combining Regex with sed/awk

Integrate regular expressions into 'sed' and 'awk' commands for advanced text filtering, substitution, and data extraction.

Regex with sed and awk

Welcome to the final lesson on Regular Expressions! We've learned about the power of regex for pattern matching.

Now, let's combine that power with two essential Linux tools: sed (stream editor) and awk (pattern scanning and processing language). This integration allows for highly advanced text filtering, substitution, and data extraction.

sed: Filtering with Regex

sed can use regular expressions to filter lines. The /pattern/ address allows sed to apply commands only to lines that match the given regex.

The -n option suppresses default output, and p explicitly prints matching lines.

echo -e "apple
banana
orange" | sed -n '/an/p'

All lessons in this course

  1. Introduction to Regular Expressions (Regex)
  2. Advanced Grep with Regex
  3. Combining Regex with sed/awk
  4. Capture Groups, Backreferences & Substitution
← Back to Linux Command Line & Bash Scripting Mastery