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
| Goal | Command |
|---|---|
| Replace all “foo” with “bar” | sed 's/foo/bar/g' file |
| Replace only on lines 10-20 | sed '10,20s/foo/bar/g' file |
| Delete blank lines | sed '/^$/d' file |
| Delete line 3 | sed '3d' file |
| Print only lines 5-10 | sed -n '5,10p' file |
| Edit the file in place | sed -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’s 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’ll 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’re 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’re on macOS or BSD sed, you can’t skip the suffix, it’s required, so pass -i '' when you genuinely don’t want a backup.
How do I print only specific lines?
Pair -n with the print command and an address. The -n shuts off sed’s automatic printing, so sed -n '5,10p' file shows you lines 5 through 10 and nothing else. Forget the -n and you get a mess: every line prints, and the ones you actually wanted print twice.
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’s awk territory. They’re not rivals, really. Plenty of pipelines run both, sed scrubbing the text and awk pulling out or crunching the numbers. I lean on that combo more than I’d like to admit.
Sources & further reading
Related tools and resources
A few more command builders from the same toolkit, if sed isn’t the tool you actually needed.













