suckless unix tools
git clone git://
Log | Files | Refs | README | LICENSE

sed.1 (4029B)

      1 .Dd 2015-10-08
      2 .Dt SED 1
      3 .Os sbase
      4 .Sh NAME
      5 .Nm sed
      6 .Nd stream editor
      7 .Sh SYNOPSIS
      8 .Nm
      9 .Op Fl nrE
     10 .Ar script
     11 .Op Ar file ...
     12 .Nm
     13 .Op Fl nrE
     14 .Fl e Ar script
     15 .Op Fl e Ar script
     16 .Ar ...
     17 .Op Fl f Ar scriptfile
     18 .Ar ...
     19 .Op Ar file ...
     20 .Nm
     21 .Op Fl nrE
     22 .Op Fl e Ar script
     23 .Ar ...
     24 .Fl f Ar scriptfile
     25 .Op Fl f Ar scriptfile
     26 .Ar ...
     27 .Op Ar file ...
     29 .Nm
     30 reads line oriented output from
     31 .Ar file
     32 or stdin, applies the editing commands supplied by
     33 .Ar script
     34 or
     35 .Ar scriptfile
     36 and writes the edited stream to stdout.
     37 .Sh OPTIONS
     38 .Bl -tag -width Ds
     39 .It Fl n
     40 Suppress default printing at the end of each cycle.
     41 .It Fl r E
     42 Use extended regular expressions
     43 .It Fl e Ar script
     44 Append
     45 .Ar script
     46 to the list of editing commands.
     47 .It Fl f Ar scriptfile
     48 Append the commands from
     49 .Ar scriptfile
     50 to the list of editing commands.
     51 .El
     53 Editing commands take the form
     54 .Pp
     55 [address[,address]]function
     56 .Ss Addresses
     57 Addresses are either blank, a positive decimal integer denoting a line
     58 number, the character '$' denoting the last line of input, or a regular
     59 expression.
     60 A command with no addresses matches every line, one address matches
     61 individual lines, and two addresses matches a range of lines from the
     62 first to the second address inclusive.
     63 .Ss Functions
     64 .Bl -tag -width Ds
     65 .It Ar a Op Ar text
     66 Append text to output after end of current cycle.
     67 .It Ar b Op Ar label
     68 Branch to label.
     69 If no label is provided branch to end of script.
     70 .It Ar c Op Ar text
     71 Change.
     72 Delete addressed range and output text after end of current cycle.
     73 .It Ar d
     74 Delete pattern space and begin next cycle.
     75 .It Ar D
     76 Delete pattern space up to and including first newline and begin new
     77 cycle without reading input.
     78 If there is no newline, behave like d.
     79 .It Ar g
     80 Get.
     81 Replace the pattern space with the hold space.
     82 .It Ar G
     83 Get.
     84 Append a newline and the hold space to the pattern space.
     85 .It Ar h
     86 Hold.
     87 Replace the hold space with the pattern space.
     88 .It Ar H
     89 Hold.
     90 Append a newline and the pattern space to the hold space.
     91 .It Ar i Op Ar text
     92 Insert text in output.
     93 .It Ar l
     94 List? Write the pattern space replacing known non printing characters with
     95 backslash escaped versions (\\\\, \\a, \\b, \\f, \\r, \\t, \\v).
     96 Print bad UTF-8 sequences as \\ooo where ooo is a three digit octal
     97 number.
     98 Mark end of lines with '$'.
     99 .It Ar n
    100 Next.
    101 Write pattern space (unless
    102 .Fl n ) ,
    103 read next line into pattern space, and continue current cycle.
    104 If there is no next line, quit.
    105 .It Ar N
    106 Next.
    107 Read next line, append newline and next line to pattern space, and
    108 continue cycle.
    109 If there is no next line, quit without printing current pattern space.
    110 .It Ar p
    111 Print current pattern space.
    112 .It Ar P
    113 Print current pattern space up to first newline.
    114 .It Ar q
    115 Quit.
    116 .It Ar r file
    117 Read file and write contents to output.
    118 .It Ar s/re/text/flags
    119 Find occurences of regular expression re in the pattern space and
    120 replace with text.
    121 A '&' in text is replaced with the entire match.
    122 A \\d where d is a decimal digit 1-9 is replaced with the corresponding
    123 match group from the regular expression.
    124 \\n represents a newline in both the regular expression and replacement
    125 text.
    126 A literal newline in the replacement text must be preceded by a \\.
    127 .Pp
    128 Flags are
    129 .Bl -tag -width Ds
    130 .It Ar n
    131 A positive decimal number denoting which match in the pattern space
    132 to replace.
    133 .It Ar g
    134 Global.
    135 Replace all matches in the pattern space.
    136 .It Ar p
    137 Print the pattern if a replacement was made.
    138 .It Ar w file
    139 Write the pattern space to file if a replacement was made.
    140 .El
    141 .It Ar t Op Ar label
    142 Test.
    143 Branch to corresponding label if a substitution has been made since the
    144 last line was read or last t command was executed.
    145 If no label is provided branch to end of script.
    146 .It Ar w file
    147 Write pattern space to file.
    148 .It Ar x
    149 Exchange hold space and pattern space.
    150 .It Ar y/set1/set2/
    151 Replace each occurrence of a character from set 1 with the corresponding
    152 character from set 2.
    153 .It Ar :label
    154 Create a label for b and t commands.
    155 .It Ar =
    156 Write current input line number to output.
    157 .El