Skip to content
NSNormandin SystemsTHE EVERYDAY TOOLBOXMain site
</>

Development / YOUR EVERYDAY TOOLBOX

Sed cheatsheet

sed unix command cheatsheet

✓ Free to use✓ No account neededHow to use this tool ↓
YOUR WORKSPACESee an example ↗

Opening your tool…

Runs in your browser. Check important results and keep a copy of your original files.

THE PRACTICAL GUIDE · NORMANDIN SYSTEMS

Get more from Sed cheatsheet

Sed Cheatsheet summarizes common stream-editing expressions for selecting lines and transforming text. sed processes text as a stream and can print transformed output without changing the source file. In-place editing is a separate choice, and regular-expression syntax or command flags can differ between GNU and BSD implementations. A cheatsheet works best as a memory aid while you practice a concrete task. Read the command or syntax together with its arguments, placeholders, and surrounding context. Similar-looking options can have very different meanings, and an example written for one platform or version may need adjustment elsewhere. Keep the reference beside a small test case, use read-only examples first when possible, and check the relevant help output before applying an unfamiliar command to valuable files or a running service.

Guide updated October 13, 2026

How to use this tool

  1. Identify the operation you want to perform and find the matching section of the reference. Read the whole example before copying any part of it.
  2. Try the expression on a short sample and inspect standard output before considering an in-place edit.
  3. Review the example below and compare its expected behavior with a small sample of your own input before continuing.
  4. Try the adapted example on a small test case, compare the result with the explanation, and save the command with a note about the context in which it works.

SEE IT IN PRACTICE

A worked example

EXAMPLE INPUT
sed 's/cat/dog/' applied to the line cat cat
RESULT / WHAT TO EXPECT
dog cat

Without the global flag, this substitution changes the first match on the line, making it a useful example of flag-dependent behavior.

Substitution scope is explicit

A substitution command normally changes the first match on a line unless a global or other relevant modifier changes that behavior. Addressing can restrict which lines are processed, and regular-expression mode affects pattern syntax. Test these dimensions separately: which lines are selected, which text matches, and how many matches are replaced. A small sample containing repeated occurrences is much more informative than a single matching word because it reveals the actual scope of the expression.

Output first, in-place editing later

sed can show transformed text without modifying the original file. Use that behavior to inspect the result before selecting an in-place option. GNU and BSD variants differ in some flags and syntax, including details around in-place backups. Shell quoting is another layer that must preserve the intended script. Keep the source and review boundaries around special characters, newlines, and delimiters. For complex structured data, a format-aware tool may be more appropriate than extending a fragile text substitution.

When this tool is useful

  • Review a text substitution pattern
  • Understand per-line replacement behavior
  • Prepare a cautious stream-editing command

Tips for a better result

  • Check delimiters, escaping, matching scope, and whether the expression changes one occurrence or all intended occurrences.
  • Replace example paths, identifiers, and names deliberately. Copying a reference command unchanged can target a different file, branch, service, or environment from the one you intended.
  • Keep the source and the settings used for this result together. That makes a later comparison or correction easier, especially when another person needs to reproduce the same outcome.

Frequently asked questions

What needs checking before an in-place sed edit?

An in-place edit can overwrite valuable data, and shell quoting adds another interpretation layer. Keep a source copy and verify implementation-specific options.

Does this page execute the examples?

The cheatsheet is a reference. You read its examples and use them in your own editor, terminal, or application. Understand the effect and adapt placeholders before running commands in an environment that contains important data.

What if an example behaves differently on my system?

Check your installed version, platform, shell, and configuration. Read the command help or language documentation for that environment. References summarize common behavior, while available options and defaults can vary between implementations.

What happens to the information I enter?

The utility processes your input in this browser. Some tools retain field values in browser storage or the URL; avoid entering secrets in shareable fields. Page and asset requests still go to the hosting provider. Read the privacy and offline-use notes for details.