Intuitive find and replace CLI (sed alternative)

https://news.ycombinator.com/rss Hits: 3
Summary

sd - s earch & d isplace sd is an intuitive find & replace CLI. The Pitch Why use it over any existing tools? Painless regular expressions. sd uses regex syntax that you already know from JavaScript and Python. Forget about dealing with quirks of sed or awk - get productive immediately. String-literal mode. Non-regex find & replace. No more backslashes or remembering which characters are special and need to be escaped. Easy to read, easy to write. Find & replace expressions are split up, which makes them easy to read and write. No more messing with unclosed and escaped slashes. Smart, common-sense defaults. Defaults follow common sense and are tailored for typical daily use. Comparison to sed While sed does a whole lot more, sd focuses on doing just one thing and doing it well. Here are some cherry-picked examples where sd shines. Simpler syntax for replacing all occurrences: sd: sd before after sed: sed s/before/after/g Replace newlines with commas: sd: sd ' ' ',' sed: sed ':a;N;$!ba;s/ /,/g' Extracting stuff out of strings containing slashes: sd: echo "sample with /path/" | sd '.*(/.*/)' '$1' sed: echo "sample with /path/" | sed -E 's/.*(\\/.*\\/)/\1/g' With sed, you can make it better with a different delimiter, but it is still messy: echo "sample with /path/" | sed -E 's|.*(/.*/)|\1|g' In place modification of files: sd: sd before after file.txt sed: sed -i -e 's/before/after/g' file.txt With sed, you need to remember to use -e or else some platforms will consider the next argument to be a backup suffix. Benchmarks Simple replacement on ~1.5 gigabytes of JSON hyperfine --warmup 3 --export-markdown out.md \ ' sed -E "s/\"/ ' " ' " ' /g" *.json > /dev/null ' \ ' sed "s/\"/ ' " ' " ' /g" *.json > /dev/null ' \ ' sd "\"" " ' " ' " ' " *.json > /dev/null ' Command Mean [s] Min…Max [s] sed -E "s/\"/'/g" *.json > /dev/null 2.338 ± 0.008 2.332…2.358 sed "s/\"/'/g" *.json > /dev/null 2.365 ± 0.009 2.351…2.378 sd "\"" "'" *.json > /dev/null 0.997 ± 0.006 0.987…1.007 Resul...

First seen: 2025-09-02 12:51

Last seen: 2025-09-02 14:51