sd
Intuitive find & replace CLI (sed alternative)
sd is a fast Rust command-line tool for finding and replacing text in files, with a cleaner syntax than sed, modern regex support, and 2-12x better performance on regex-heavy tasks.
sd is a command-line tool for finding and replacing text in files or piped input. It is written in Rust and designed as a simpler alternative to the traditional sed tool that ships on Unix-like systems. The basic usage is just sd followed by the text to find and the text to replace it with, and optionally one or more file names to modify in place.
The main differences from sed are in readability and regex syntax. sed uses a compressed format where the find pattern, replacement, and flags are all packed into one argument separated by slashes, which makes expressions with slashes in them messy to write. sd splits the find and replacement into two separate arguments, so there is nothing to escape. The regex syntax also matches what you would find in JavaScript or Python rather than the older POSIX-style syntax sed uses.
By default, sd processes text one line at a time, which keeps memory usage low and works well for most replacements. An across mode is available with the -A flag when you need a pattern to span multiple lines, for example to replace newlines with commas. The README includes benchmark results showing sd runs roughly 2 to 12 times faster than sed depending on the task, with the larger speedups on regex-heavy workloads.
A plain string mode turns off regex interpretation entirely, which is useful when the text you are searching for contains characters that would normally have special meaning in a regex pattern. A preview flag lets you see what changes would be made before committing them to a file.
Installation is available through the Rust package manager cargo or through various system package managers. The README lists packaging status across distributions.
Where it fits
- Replace all occurrences of an old function name across multiple source files in one command.
- Transform text piped from another command, such as replacing commas with newlines in CSV output.
- Use plain-string mode to safely replace text containing dots, brackets, or other regex special characters without escaping them.
- Preview what changes sd would make to a file before committing them.