Is there a basic tutorial for grep, awk and sed?

Typically, grep is used for search operations, sed is used for search and replace operations and awk is particularly well suited for tabular data and has a lower learning curve than some alternatives. There are overlapping features between these tools as well, see: When to use grep, less, awk, sed

grep

  • Documentation: man grep, info grep, GNU grep online manual
  • An introduction to grep and egrep
  • grep tutorial
  • ripgrep - alternate implementation, recursive by default, respects .gitignore, Rust/PCRE2 regex, SIMD, etc
  • Ebook on GNU grep and ripgrep

sed

  • Documentation: man sed, info sed, GNU sed online manual
  • Sed - An Introduction and Tutorial
  • Sed by Example Part 1, Part 2, Part 3
  • sed tutorial
  • Ebook on GNU sed one-liners

awk

  • Documentation: man awk, info awk, info gawk, GNU awk online manual
  • AWK: A Tutorial and Introduction
  • Awk by Example Part 1, Part 2, Part 3
  • An AWK Primer (alt link)
  • Ebook on GNU awk one-liners

Further Reading

  • RegularExpressions.info

The O'Reilly sed and awk book is great for er sed and awk.


I wrote a book on sed—Definitive Guide to sed—that includes a tutorial. It fully covers sed, as well as related commands like grep, tr, head and tail. Also fully covers regular expressions much better than I've seen elsewhere.

I agree with others that solid understanding regular expressions well is very important. I also agree that sed is best used for simpler tasks, more complex scripts quickly get obscure.

I disagree that awk is obsolete, just the opposite. It's like many unix things (e.g., vi), there is a learning curve, but it's worth it.

I disagree with the suggestion to use awk in place of grep. Does not make sense in my experience. grep is so great and simple.

Tags:

Grep

Awk

Sed