TL;DR — Quick Summary

sd is a modern sed alternative for search-and-replace. Uses familiar regex syntax, no escaping nightmares, supports string literal mode. Just sd 'old' 'new'.

sd makes find-and-replace simple. No more fighting with sed’s arcane syntax — just sd 'old' 'new'. It handles regex by default and literal strings with -F.

Installation

# macOS
brew install sd

# Arch Linux
sudo pacman -S sd

# Cargo
cargo install sd

# Ubuntu/Debian (via cargo)
cargo install sd

Usage

# Basic replacement (stdin)
echo 'hello world' | sd 'world' 'Rust'
# → hello Rust

# Replace in file (in-place)
sd -i 'old_name' 'new_name' config.toml

# Multiple files
sd -i 'TODO' 'DONE' src/*.rs

# Literal mode (no regex — perfect for code)
sd -F 'Vec<String>' 'Vec<&str>' src/main.rs
sd -F 'console.log(' 'logger.info(' src/*.js

# Regex with capture groups
sd '(\d+)px' '${1}rem' styles.css
sd '(\w+)\.old' '$1.new' manifest.txt

# Preview changes (don't write)
cat file.txt | sd 'pattern' 'replacement'

# Use with find for recursive replacement
find . -name '*.md' -exec sd -i 'oldterm' 'newterm' {} +

# Combine with fd for even better experience
fd -e rs | xargs sd -i 'old_api' 'new_api'

Comparison: sd vs sed

# sed: Replace "hello" with "world"
sed 's/hello/world/g' file.txt
# sed: Escape slashes in paths
sed 's/\/usr\/local\/bin/\/opt\/bin/g' file.txt
# sed: In-place (differs between GNU and BSD!)
sed -i 's/old/new/g' file.txt      # GNU
sed -i '' 's/old/new/g' file.txt   # BSD/macOS

# sd: Same operations, much simpler
sd 'hello' 'world' file.txt
sd '/usr/local/bin' '/opt/bin' file.txt
sd -i 'old' 'new' file.txt         # Same on all platforms
Featuresdsedperl -pe
SyntaxIntuitiveCrypticComplex
EscapingMinimalHeavyHeavy
Literal mode-F flagNo-Q flag
Capture groups$1, $2\1, \2$1, $2
Cross-platformIdenticalGNU vs BSDIdentical
SpeedFast (Rust)Fast (C)Moderate

Summary

  • sd is a modern, intuitive sed replacement — sd 'old' 'new'
  • No delimiter escaping, no GNU/BSD differences
  • String literal mode (-F) for code refactoring without regex headaches
  • Regex with $1, $2 capture groups by default
  • Combine with fd for powerful recursive find-and-replace