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.txtReplace first match on each line
sed 's/foo/bar/g' file.txtReplace all matches on each line
sed -n '10,20p' file.txtPrint only specific line range
sed '/^$/d' file.txtDelete empty lines
sed -i 's/old/new/g' file.txtEdit file in-place
sed -E 's/[0-9]+/<num>/g' file.txtUse 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