sed
Stream editor for filtering and transforming text. Great for in-place edits, line-based replacements, and quick data cleanup.
Synopsis
sed [options] 'script' file(s)
Core Options
-nSuppress automatic printing; use 'p' to print explicitly.
-EUse extended regular expressions.
-iEdit files in place (use -i.bak to keep a backup).
-e 'script'Add multiple editing commands.
-f fileRead sed commands from a file.
Usage Examples
Simple Replace
Replace all occurrences of 'foo' with 'bar'.
sed 's/foo/bar/g' input.txtPrint a Line Range
Print lines 10 to 20 only.
sed -n '10,20p' input.txtDelete Blank Lines
Remove empty lines from a file.
sed '/^$/d' input.txtIn-place Edit with Backup
Replace tabs with spaces and keep a .bak file.
sed -i.bak 's/\t/ /g' config.txtMultiple Commands
Delete comments and trim trailing spaces.
sed -e 's/#.*$//' -e 's/[[:space:]]*$//' file.confBuilt for builders.