Build sed command

Build a sed command for a precise text replacement or line operation.

freeworks offlinenothing uploaded
ToolSed Command Builder
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

A selected sed command combines an address, command letter, and escaped pattern or replacement. The preview shows the shell command without executing it.

  • The familiar s/old/new/g form replaces every match.
  • The file remains untouched until the command is run.

Worked example

Replace foo with bar, every match, in place, lines 2 to 5
Case insensitive with a line range
Input
											Find: foo
Replace: bar
										
Output
												Command: sed 's/foo/bar/g' FILENAME
Delimiter used: /
Flags used: g
Flags explained: g replaces every match on each line, not just the first.
Notes: Replace FILENAME with the path to your file. On macOS (BSD sed) -i needs an argument, use -i ' ' instead of -i.
											

When to use this

Release scripts, Unix pipelines, and migration recipes build sed commands.

Edge cases

  • A slash in a pattern needs escaping or another delimiter.
  • An ampersand in replacement text expands to the match unless escaped.
  • GNU and BSD sed differ in some appended flags.

References