Grep Cheatsheet

Grep pattern matching, regular expressions, and text search techniques

Shell Utilities6 commandsbeginner

Overview

Grep searches text using regular expressions and prints matching lines.

Why It Matters

Grep is essential for searching and filtering text patterns in files and command output.

Essential Commands

grep "error" app.log

Find matching lines in file

grep -R "TODO" src/

Recursively search in directory

grep -n "function" index.js

Show line numbers for matches

grep -i "warning" app.log

Case-insensitive search

grep -v "debug" app.log

Exclude matching lines

grep -E "cat|dog" animals.txt

Use extended regex patterns

Quick Start

Begin by learning use basic and extended regex patterns

Key Concepts

Use basic and extended regex patterns

Combine with pipes for powerful text processing

Master options like -v, -c, and -A

Pro Tips

  • Combine multiple commands for powerful workflows
  • Use aliases to speed up your command entry
  • Create scripts to automate repetitive tasks

Common Pitfalls to Avoid

  • Forgetting to check the documentation for edge cases
  • Running commands without understanding their full impact
  • Not testing changes in a safe environment first

Related Resources

9 items