sed Command Generator

Build a sed command without memorizing the syntax, with line addressing and an in-place flag that warns first.

This sed command generator builds the exact sed line you need without making you memorize the syntax again. Pick an operation (substitute, delete lines, print a range, insert or append text) then point it at the lines you care about: every line, a single number, a range like 10,20, or a regex pattern. Toggle the global and ignore case flags, and the command rebuilds live as you type while a labelled table explains every part. When you flip on in-place editing it warns you, because the bare -i flag rewrites the file with no undo and has ruined plenty of files. It even swaps the delimiter when your pattern holds a slash. Everything runs in your browser, so nothing you type ever leaves the page.

100% in your browser. Nothing you type ever leaves this page.

sed command generator

Need a sed command and don't feel like memorizing the syntax again? Pick what you want done. Substitute text, delete lines, print a range, drop in a line. Set the pattern and point it at the lines you care about. Then decide if it should rewrite the file or just show you. The command rebuilds as you type, and each piece gets explained. Flip on in-place editing and you'll get a warning, because that flag has ruined plenty of files. Nothing leaves your browser.

$

What this sed command generator does

sed is the stream editor. It reads text line by line as it flows past, tweaking it on the way through. Honestly it's the quickest way I know to swap strings, drop lines you don't want, or script an edit across a config file. The catch is the language. It's terse to the point of cryptic: one letter for the command, an optional address picking which lines, then a flag or two. All that density is exactly why sed gets misused, and the -i flag (the one that rewrites the file for real) is where people get burned. So this thing builds the command for you and labels every part.

The skeleton is sed '[address]command' file. The address says which lines: a number, a range like 10,20, a /regex/. Skip it and sed touches every line. Then the command. That's the actual operation. s substitutes, d deletes, p prints, and i with a handle insert and append. Substitute has its own little shape, s/find/replace/flags, and the g at the end is what makes it hit every match on a line instead of stopping at the first one. Easy thing to forget.

The operations you will use most

GoalCommand
Replace all "foo" with "bar"sed 's/foo/bar/g' file
Replace only on lines 10-20sed '10,20s/foo/bar/g' file
Delete blank linessed '/^$/d' file
Delete line 3sed '3d' file
Print only lines 5-10sed -n '5,10p' file
Edit the file in placesed -i 's/foo/bar/g' file

In-place editing and backups

Out of the box, sed just prints the result to your terminal and leaves the file alone. That's the safe way to preview, and you should lean on it. Add -i and it rewrites the file in place, no undo. Since there's no undo, GNU sed lets you hang a suffix on the flag to keep a copy: -i.bak saves the original off to the side as file.bak before it edits. My rule, and maybe it's just paranoia from one bad afternoon, is to run it once clean, eyeball the output, then add the flag. One more thing that trips people moving between machines: on macOS and BSD the suffix isn't optional. You have to give it something, even an empty string (-i '').

Regex and delimiters

By default the find pattern is a basic regular expression, so you'll be escaping things, or you reach for -E and get extended regex instead. Here's the trick worth knowing. When your pattern has slashes in it (file paths, classic case) you don't have to backslash every single one. sed takes whatever character you put right after s as the delimiter, so s|/old/path|/new/path|g just works and reads cleaner. This generator notices a slash in your text and quietly swaps the delimiter for you.

Privacy and how this tool runs

It's all JavaScript, running right here in your browser. The patterns and file names you type stay on your machine, nothing gets sent or logged. There's no server doing the work, so the page keeps building commands even with the connection down.

Frequently asked questions

How do I replace text in a file with sed?

sed 's/old/new/g' file prints the changed text to your screen. Swap in sed -i 's/old/new/g' file when you actually want the file rewritten. That g on the end matters more than it looks: it catches every occurrence on a line. Leave it off and sed only touches the first match per line, which is almost never what you meant.

What does the g flag do?

On its own, substitute only hits the first match on a line and moves on. The g (global) flag tells it to keep going and replace every match. There is a lesser-known variant too: stick a number in front of g and it starts from that match onward, so s/a/b/2g skips the first one and changes the rest.

How do I delete lines matching a pattern?

Put a pattern in front of the delete command. sed '/pattern/d' file drops every line that contains it. A couple you will use constantly: sed '/^$/d' strips blank lines, sed '3d' kills line 3 by number. All of that prints to screen first. Tack on -i when you are ready to commit the deletions to the file itself.

How do I edit a file in place safely?

Run it without -i first and read the output. Honestly that one habit saves more files than any backup does. Once it looks right, switch to -i.bak so sed writes the change and tucks the original away as file.bak. And if you are on macOS or BSD sed, you cannot skip the suffix, it is required, so pass -i '' when you genuinely do not want a backup.

When should I use awk instead of sed?

sed is your tool when the work is line by line, a substitution here, a deleted line there. The moment you start thinking in columns and fields, or you need actual logic across records, that is awk territory. They are not rivals, really. Plenty of pipelines run both, sed scrubbing the text and awk pulling out or crunching the numbers.