SED(1)

NAME
sed - stream editor

SYNOPSIS
sed [-nrE] script [file ...]
sed [-nrE] -e script [-e script] ... [-f scriptfile] ... [file ...]
sed [-nrE] [-e script] ... -f scriptfile [-f scriptfile] ... [file ...]

DESCRIPTION
sed reads line oriented output from file or stdin, applies the editing commands supplied by script or scriptfile and writes the edited stream to stdout.

OPTIONS

-n  Suppress default printing at the end of each cycle.

-r -E
    Use extended regular expressions

-e script
    Append script to the list of editing commands.

-f scriptfile
    Append the commands from scriptfile to the list of editing commands.

EXTENDED DESCRIPTION
Editing commands take the form:

[address[,address]]function

Commands can be separated by ';' or by a new line.

Multiple functions for the specified address (or address-range) can be enclosed in blocks with '{' and '}':

[address[,address]] { function ; function }

  Addresses
Addresses are either blank, a positive decimal integer denoting a line number, the character '$' denoting the last line of input, or a regular expression (in the format / regexp/). A command with no addresses matches every line, one address matches individual lines, and two addresses matches a range of lines from the first to the second address inclusive.

The character '!' may be appended after the addresses, in which case the function is executed only if the addresses don't match.

  Functions

a [text]
    Append text to output after end of current cycle.

b [label]
    Branch to label. If no label is provided branch to end of script.

c [text]
    Change. Delete addressed range and output text after end of current cycle.

d   Delete pattern space and begin next cycle.

D   Delete pattern space up to and including first newline and begin new cycle without reading input. If there is no newline, behave like d.

g   Get. Replace the pattern space with the hold space.

G   Get. Append a newline and the hold space to the pattern space.

h   Hold. Replace the hold space with the pattern space.

H   Hold. Append a newline and the pattern space to the hold space.

i [text]
    Insert text in output.

l   List? Write the pattern space replacing known non printing characters with backslash escaped versions (\\, \a, \b, \f, \r, \t, \v). Print bad UTF-8 sequences as \ooo where ooo is a three digit octal number. Mark end of lines with '$'.

n   Next. Write pattern space (unless -n), read next line into pattern space, and continue current cycle. If there is no next line, quit.

N   Next. Read next line, append newline and next line to pattern space, and continue cycle. If there is no next line, quit without printing current pattern space.

p   Print current pattern space.

P   Print current pattern space up to first newline.

q   Quit.

r file
    Read file and write contents to output.

s/re/text/flags
    Find occurences of regular expression re in the pattern space and replace with text. A '&' in text is replaced with the entire match. A \d where d is a decimal digit 1-9 is replaced with the corresponding match group from the regular expression. \n represents a newline in both the regular expression and replacement text. A literal newline in the replacement text must be preceded by a \.

    Flags are

    n   A positive decimal number denoting which match in the pattern space to replace.

    g   Global. Replace all matches in the pattern space.

    p   Print the pattern if a replacement was made.

    w file
        Write the pattern space to file if a replacement was made.

t [label]
    Test. Branch to corresponding label if a substitution has been made since the last line was read or last t command was executed. If no label is provided branch to end of script.

w file
    Write pattern space to file.

x   Exchange hold space and pattern space.

y/set1/set2/
    Replace each occurrence of a character from set 1 with the corresponding character from set 2.

:label
    Create a label for b and t commands.

#comment
    The comment extends until the next newline.

=   Write current input line number to output.