Sed Cheatsheet

Sed stream editor for text manipulation, substitution, and transformation

Shell Utilities6 commandsintermediate

Overview

Sed is a non-interactive stream editor for filtering and transforming text.

Why It Matters

Sed is a powerful tool for batch editing and transforming text streams efficiently.

Essential Commands

sed 's/foo/bar/' file.txt

Replace first match on each line

sed 's/foo/bar/g' file.txt

Replace all matches on each line

sed -n '10,20p' file.txt

Print only specific line range

sed '/^$/d' file.txt

Delete empty lines

sed -i 's/old/new/g' file.txt

Edit file in-place

sed -E 's/[0-9]+/<num>/g' file.txt

Use extended regex replacement

Quick Start

Begin by learning master substitution patterns (s///)

Key Concepts

Master substitution patterns (s///)

Use ranges and addresses for selective editing

Apply transformations in pipelines

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