sd — Intuitive Find & Replace CLI, a Friendlier Alternative to sed
sd replaces sed for most find-and-replace needs with a far simpler syntax. No escaping madness, no BRE/ERE confusion, no differences between GNU and BSD — just sed 99% of us actually wanted.
What it is
sd is a command-line find-and-replace tool written in Rust that serves as a simpler alternative to sed. It takes two arguments -- pattern and replacement -- and handles the common case of text substitution without sed's cryptic syntax, escaping rules, or BSD vs GNU behavioral differences.
sd targets developers and system administrators who use sed primarily for find-and-replace and want a tool that works the same way on every platform. The regex engine uses Rust's regex crate with Perl-like syntax, supporting non-greedy quantifiers, lookarounds, and named capture groups.
How it saves time or tokens
Sed requires escaping parentheses for capture groups in BRE mode, uses different flags on BSD (macOS) and GNU (Linux), and has a multi-letter command language that most users never need. sd eliminates all of this. The pattern is a regex, the replacement uses $1 $2 for capture groups, and in-place editing is a flag.
The preview flag (-p) shows what would change without modifying files, preventing accidental edits in scripts and CI pipelines.
How to use
- Install sd:
# macOS
brew install sd
# Cargo
cargo install sd --locked
- Basic find and replace from stdin:
echo 'hello world' | sd world everyone
# hello everyone
- In-place file editing with regex:
# Replace version strings using capture groups
sd 'v(\d+)\.(\d+)\.(\d+)' 'version_$1_$2_$3' changelog.md
# Preview before applying
sd -p 'foo' 'bar' *.md
Example
Common sd recipes for development workflows:
# Rename a function across files
sd 'oldFunction' 'newFunction' src/*.go
# Fix import paths
sd 'github.com/old-org/repo' 'github.com/new-org/repo' **/*.go
# Literal string mode (no regex)
sd -s 'https://old-url.com' 'https://new-url.com' config.yaml
# Pipe from find
find . -name '*.json' | xargs sd '"debug": true' '"debug": false'
Related on TokRepo
- Automation Tools -- CLI utilities for developer workflow automation
- AI Tools for Coding -- Developer productivity tools
Common pitfalls
- sd uses Perl-like regex by default, not POSIX. If you are porting a sed command, capture groups use
$1not\1in the replacement string. - The
-sflag switches to literal string matching. Without it, characters like.and*are treated as regex metacharacters, which can cause unexpected matches. - sd does not support sed's multi-line addressing, delete commands, or hold space. For complex stream editing beyond find-and-replace, sed or awk is still needed.
Frequently Asked Questions
sd focuses on find-and-replace with a clean two-argument interface. It drops sed's command language, escaping inconsistencies, and BSD vs GNU differences. For the 90% of sed usage that is simple substitution, sd is easier and more consistent.
Yes. Use parentheses in the pattern and $1, $2, etc. in the replacement. Named groups are also supported with Rust regex syntax. No escaping of parentheses is needed.
Yes. By default sd modifies files in place when you pass file arguments. Use the -p flag to preview changes without writing, which is recommended before batch operations.
sd uses Rust's regex crate, which supports Perl-like syntax including non-greedy quantifiers, lookaheads, lookbehinds, and Unicode character classes. It does not support backreferences in patterns.
For simple substitutions, sd and modern sed perform similarly. The primary advantage of sd is usability, not speed. The Rust implementation is efficient, but the real time savings come from not debugging escaping issues.
Citations (3)
- sd GitHub— sd is a Rust find-and-replace CLI alternative to sed
- Rust regex crate— Rust regex crate with Perl-like syntax
- GNU sed Manual— sed stream editor POSIX specification
Related on TokRepo
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.