Sed Quick Reference Page - Bruce Barnett

Home Magic Search About Donate

Last modified: Mon Dec 7 09:58:22 2020

You can buy me a coffee

I would appreciate it if you occasionally buy me a coffee as it helps maintain this site. Thanks to those who do!

Check out my Sed Reference Chart (pdf)

Here is a quick reference to the major parts of SED, with links to my extended tutorial on commands, flags and options. I've placed it on this page to make my web site more mobile-friendly.

Unix Concepts

Unix Concepts
Bypassing the shell by quoting characters
Regular Expressions

Sed Concepts

Sed Concepts
Table of Contents
The basic Substitute operation "s"
Addresses (limiting the operation to a subset of lines)
Patterns - using Regular Expressions
Flags that operate on Patterns
Command Line Options
GNU sed Command Line Options
Adding, Changing, Inserting new lines
Working with Multiple Line patterns
Summary of Commands

Pattern Flags (used after a regular expression)

Sed Pattern Flags
/g - Global
/I - Ignore Case
/p - Print
/w filename - Write Filename

Sed command line options

Sed Command Line options
Short Option (Long option)Sed version
-n Classic
-e scriptClassic
-f scriptfile Classic
-e script (--expression=script) GNU sed
-f scriptfile (--file=scriptfile) GNU sed
-h (--help) GNU sed
-n (--quiet --silent) GNU sed
-V (--version) GNU sed
-r (--regexp-extended)GNU sed
-i[SUFFIX] (--in-place[=SUFFIX])GNU sed
-l N (--line-length=N)GNU sed
-b (--binary)GNU sed
-s (--separate)GNU sed
-z (--null-data)GNU sed
-u (--unbuffered)GNU sed
(--follow-symlinks)GNU sed
(--posix)GNU sed
-i SUFFIXMac OS X, FreeBSD
-aMac OS X, FreeBSD
-lMax OS X, FreeBSD
-EMac OS X, FreeBSD
-rFreeBSD
-I SUFFIXFreeBSD

Sed operational commands

Sed Commands
: label
# comment
{....} Block
= - print line number
a \ - Append
b label - Branch
c \ - change
d and D - Delete
g and G - Get
h and H - Hold
i \ - Insert
l - Look
n and N - Next
p and P - Print
q - Quit
r filename - Read File
s/..../..../ - Substitute
t label - Test
w filename - Write Filename
x - eXchange
y/..../..../ - Transform

I hope you find this useful.