sd
An intuitive find-and-replace CLI tool — a simpler, faster alternative to sed.
sd is a find-and-replace command-line tool that aims to be a simpler, more
ergonomic alternative to sed. It uses standard regex syntax (rather than POSIX
regex), supports literal string replacement without escaping, and works
consistently across platforms.
Features
- Intuitive syntax —
sd find replaceinstead ofsed 's/find/replace/g' - Standard regex — uses Rust's
regexcrate, not arcane POSIX syntax - Literal mode — replace fixed strings without worrying about escaping special characters
- In-place file editing — modify files directly without temp file gymnastics
- Multiline support — patterns can match across line boundaries
- Preview mode — pipe output to see changes before committing them
Installation
cargo install sd
Or via your system package manager:
# Debian / Ubuntu
apt install sd
# Fedora
dnf install sd
# macOS
brew install sd
# Arch Linux
pacman -S sdUsage
# Basic find and replace in a string
echo 'hello world' | sd 'world' 'Rust'
# Replace in a file (in-place)
sd 'foo' 'bar' file.txt
# Replace across multiple files
sd 'foo' 'bar' src/*.rs
# Use regex capture groups
echo '2024-01-15' | sd '(\d{4})-(\d{2})-(\d{2})' '$3/$2/$1'
# Output: 15/01/2024
# Literal string mode (no regex), useful for replacing strings with special characters
sd -F 'file.name' 'file_name' config.txt
# Preview changes without modifying the file
sd 'old_api' 'new_api' src/main.rsComparison with sed
# sed — replace all occurrences
sed -i 's/old/new/g' file.txt
# sd — same thing, far less noise
sd 'old' 'new' file.txt
# sed — backreference syntax
sed 's/\(foo\)\(bar\)/\2\1/'
# sd — backreference syntax (standard)
sd '(foo)(bar)' '$2$1'
sd shines in scripts and one-liners where sed's idiosyncratic syntax would
otherwise slow you down or introduce subtle bugs.