sed

CLI

Stream editor for filtering and transforming text.

Stream editor for in-place text substitution

4 of 6 recipes verified by execution · 2026-09-17#text#replace#stream#regex

Verified commands

Executed by our harness on the platforms shown; the assertion checked the actual result, not just the exit code.

Replace text in a file in place (macOS/BSD sed)

macOS only

Verified macOS · 2026-09-17
sed -i '' 's/old/new/g' file.txt
Common failures (1)
  • on Linux: sed: can't read : No such file or directoryGNU sed takes no argument after -i: use sed -i 's/old/new/g' file.txt

Replace text in a file in place (Linux/GNU sed)

Linux only

Verified Linux · 2026-09-17
sed -i 's/old/new/g' file.txt
Common failures (1)
  • on macOS: sed: 1: "file.txt": invalid command codeBSD sed needs an explicit backup suffix: sed -i '' 's/old/new/g' file.txt

Replace text in a file in place (portable, any OS)

Verified macOS · Linux · 2026-09-17
perl -pi -e 's/old/new/g' file.txt

Replace text across all files in a directory (portable)

Verified macOS · Linux · 2026-09-17
grep -rl 'old' . | xargs perl -pi -e 's/old/new/g'
Common failures (1)
  • binary or .git files modifiedrestrict with --include: grep -rl --include='*.ts' 'old' src | xargs perl -pi -e 's/old/new/g'
Fallbackrg -l 'old' . | xargs perl -pi -e 's/old/new/g'

More recipes

Curated from documentation and usage. Percentages are estimates, not measurements.

Delete lines matching pattern

~97% est.
sed '/pattern/d' file.txt

Print specific line number

~99% est.
sed -n '5p' file.txt

Install

Homebrewbrew install gnu-sed

Agent notes

When to use
Simple find-and-replace in files or streams
Quick examples
  • sed 's/foo/bar/g' file.txt
  • sed -i 's/old/new/g' *.txt

Use from an agent

curl -s https://clihub.com/api/tools/sed | jq '.agentHints.provenRecipes[] | {task, command, verified}'

Or call get_tool with slug sed on the MCP server at https://clihub.com/mcp.

Homepage ↗GPL-3.00 views