• Latest
  • Trending
  • All
sed Command Generator: Build Substitute, Delete and Print Commands - cover image

sed Command Generator: Build Substitute, Delete and Print Commands

June 14, 2026
ssh command cheatsheet

SSH Command Cheatsheet: Connect, Keys, scp, Tunnels (2026)

June 16, 2026
chmod-chown-cheatsheet

chmod and chown Cheatsheet: Linux Permissions, Decoded (2026)

June 16, 2026
systemctl-journalctl-cheatsheet

systemctl + journalctl Cheatsheet: Services and Logs (2026)

June 16, 2026
grep-cheatsheet

The grep Cheatsheet: Search a File, Search a Tree (2026)

June 16, 2026
rsync-cheatsheet

The rsync Cheatsheet: Mirror, Sync, Copy Over SSH (2026)

June 16, 2026
curl-cheatsheet

curl Cheatsheet: Download Files and Test APIs (2026)

June 16, 2026
iptables-vs-nftables-cheatsheet cheatsheet

iptables vs nftables: Linux Firewall Cheatsheet, Side by Side

June 16, 2026
nmcli-cheatsheet cheatsheet

nmcli Cheatsheet: Wi-Fi and Network Connections From the Linux Terminal

June 16, 2026
powershell-networking-cheatsheet cheatsheet

PowerShell Networking Cheatsheet: Test-NetConnection, IP, DNS (2026)

June 16, 2026
tar command cheatsheet

The tar Command Cheatsheet: Create, Extract, Stop Guessing (2026)

June 16, 2026
Linux find command cheatsheet

The find Command Cheatsheet: Every Recipe You Actually Use (2026)

June 15, 2026
Linux networking commands cheatsheet, ip and ss

Linux Networking Commands in 2026: the ip and ss Cheatsheet

June 15, 2026
  • Online Tools
  • Network Tools
  • Developer Tools
  • Security Tools
Tuesday, June 16, 2026
  • Login
People Are Geek
  • Online Tools
  • Network Tools
  • Developer Tools
  • Security Tools
No Result
View All Result
People Are Geek
No Result
View All Result
Home Developer Tools

sed Command Generator: Build Substitute, Delete and Print Commands

by People Are Geek
June 14, 2026
in Developer Tools, Online Tools
0
sed Command Generator: Build Substitute, Delete and Print Commands - cover image
0
SHARES
7
VIEWS
Share on FacebookShare on Twitter

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.

$
Recommended dev gearWe may earn a commission, at no extra cost to you.
Mechanical KeyboardCheck price on Amazon →Usb C Docking StationCheck price on Amazon →Portable MonitorCheck price on Amazon →Clean Code BookCheck price on Amazon →

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’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

  • GNU sed manual
  • man7.org, sed(1) man page

Related tools and resources

A few more command builders from the same toolkit, if sed isn’t the tool you actually needed.

find Command Generator tar Command Generator rsync Command Generator chmod Calculator Common Ports List
ShareTweetPin
People Are Geek

People Are Geek

I'm Stephane, a network and systems engineer with over 15 years of hands-on experience on production infrastructure, virtualization (ESXi, Proxmox), networking, and self-hosting. Earlier in my career I built and ran a Linux resource site that became a well-known reference for sysadmins. Today I focus on cybersecurity, and I also work as a technical trainer, teaching networking and security to people who do it for a living. Everything on People Are Geek comes from real-world practice, not theory. I build every tool on this site myself, and I write about what I've actually deployed, broken, and fixed. If it's here, I've used it.

People Are Geek

Copyright © 2017 JNews.

Navigate Site

  • About PeopleAreGeek
  • Affiliate Disclosure
  • All Tools and Articles
  • Contact
  • Cookie Policy
  • Hyper-V Hub: Tools, Error Fixes and Lab Guides
  • Linux Hub: Cross-Distro Reference, Articles, Tools
  • Privacy Policy
  • Sample Page
  • Terms of Service
  • VMware vSphere & ESXi Hub: Tools, Error Fixes and Guides

Follow Us

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
No Result
View All Result
  • Online Tools
  • Network Tools
  • Developer Tools
  • Security Tools

Copyright © 2017 JNews.