1SED(1)                           User Commands                          SED(1)
2
3
4

NAME

6       sed - stream editor for filtering and transforming text
7

SYNOPSIS

9       sed [OPTION]... {script-only-if-no-other-script} [input-file]...
10

DESCRIPTION

12       Sed  is a stream editor.  A stream editor is used to perform basic text
13       transformations on an input stream (a file or input from  a  pipeline).
14       While  in  some  ways similar to an editor which permits scripted edits
15       (such as ed), sed works by making only one pass over the input(s),  and
16       is consequently more efficient.  But it is sed's ability to filter text
17       in a pipeline which particularly distinguishes it from other  types  of
18       editors.
19
20       -n, --quiet, --silent
21
22              suppress automatic printing of pattern space
23
24       -e script, --expression=script
25
26              add the script to the commands to be executed
27
28       -f script-file, --file=script-file
29
30              add the contents of script-file to the commands to be executed
31
32       -i[SUFFIX], --in-place[=SUFFIX]
33
34              edit files in place (makes backup if extension supplied)
35
36       -c, --copy
37
38              use  copy  instead  of  rename  when  shuffling files in -i mode
39              (avoids change of input file ownership)
40
41       -l N, --line-length=N
42
43              specify the desired line-wrap length for the `l' command
44
45       --posix
46
47              disable all GNU extensions.
48
49       -r, --regexp-extended
50
51              use extended regular expressions in the script.
52
53       -s, --separate
54
55              consider files as separate rather than as  a  single  continuous
56              long stream.
57
58       -u, --unbuffered
59
60              load  minimal amounts of data from the input files and flush the
61              output buffers more often
62
63       --help
64              display this help and exit
65
66       --version
67              output version information and exit
68
69       If no -e, --expression, -f, or --file option is given, then  the  first
70       non-option  argument  is  taken  as  the  sed script to interpret.  All
71       remaining arguments are names of input files; if  no  input  files  are
72       specified, then the standard input is read.
73
74       E-mail  bug  reports to: bonzini@gnu.org .  Be sure to include the word
75       ``sed'' somewhere in the ``Subject:'' field.
76

COMMAND SYNOPSIS

78       This is just a brief synopsis of sed commands to serve as a reminder to
79       those  who  already  know sed; other documentation (such as the texinfo
80       document) must be consulted for fuller descriptions.
81
82   Zero-address ``commands''
83       : label
84              Label for b and t commands.
85
86       #comment
87              The comment extends until the next newline (or the end of  a  -e
88              script fragment).
89
90       }      The closing bracket of a { } block.
91
92   Zero- or One- address commands
93       =      Print the current line number.
94
95       a \
96
97       text   Append text, which has each embedded newline preceded by a back‐
98              slash.
99
100       i \
101
102       text   Insert text, which has each embedded newline preceded by a back‐
103              slash.
104
105       q      Immediately  quit  the  sed  script  without processing any more
106              input, except that if auto-print is  not  disabled  the  current
107              pattern space will be printed.
108
109       Q      Immediately  quit  the  sed  script  without processing any more
110              input.
111
112       r filename
113              Append text read from filename.
114
115       R filename
116              Append a line read from filename.
117
118   Commands which accept address ranges
119       {      Begin a block of commands (end with a }).
120
121       b label
122              Branch to label; if label is omitted, branch to end of script.
123
124       t label
125              If a s/// has done a  successful  substitution  since  the  last
126              input  line  was  read  and  since the last t or T command, then
127              branch to label; if label is omitted, branch to end of script.
128
129       T label
130              If no s/// has done a successful  substitution  since  the  last
131              input  line  was  read  and  since the last t or T command, then
132              branch to label; if label is omitted, branch to end of script.
133
134       c \
135
136       text   Replace the selected lines with text, which  has  each  embedded
137              newline preceded by a backslash.
138
139       d      Delete pattern space.  Start next cycle.
140
141       D      Delete  up  to  the first embedded newline in the pattern space.
142              Start next cycle, but skip reading from the input  if  there  is
143              still data in the pattern space.
144
145       h H    Copy/append pattern space to hold space.
146
147       g G    Copy/append hold space to pattern space.
148
149       x      Exchange the contents of the hold and pattern spaces.
150
151       l      List out the current line in a ``visually unambiguous'' form.
152
153       n N    Read/append the next line of input into the pattern space.
154
155       p      Print the current pattern space.
156
157       P      Print  up  to  the first embedded newline of the current pattern
158              space.
159
160       s/regexp/replacement/
161              Attempt to match regexp against the pattern space.  If  success‐
162              ful,   replace  that  portion  matched  with  replacement.   The
163              replacement may contain the special character & to refer to that
164              portion  of  the  pattern  space  which matched, and the special
165              escapes \1 through \9 to refer  to  the  corresponding  matching
166              sub-expressions in the regexp.
167
168       w filename
169              Write the current pattern space to filename.
170
171       W filename
172              Write the first line of the current pattern space to filename.
173
174       y/source/dest/
175              Transliterate  the  characters in the pattern space which appear
176              in source to the corresponding character in dest.
177

Addresses

179       Sed commands can be given with no addresses, in which case the  command
180       will  be  executed for all input lines; with one address, in which case
181       the command will only be executed for  input  lines  which  match  that
182       address;  or with two addresses, in which case the command will be exe‐
183       cuted for all input lines which match  the  inclusive  range  of  lines
184       starting  from  the first address and continuing to the second address.
185       Three things to note about address ranges: the  syntax  is  addr1,addr2
186       (i.e.,  the  addresses  are separated by a comma); the line which addr1
187       matched will always be accepted, even if addr2 selects an earlier line;
188       and  if  addr2 is a regexp, it will not be tested against the line that
189       addr1 matched.
190
191       After the address (or address-range), and before the command, a !   may
192       be inserted, which specifies that the command shall only be executed if
193       the address (or address-range) does not match.
194
195       The following address types are supported:
196
197       number Match only the specified line number.
198
199       first~step
200              Match every step'th line starting with line first.  For example,
201              ``sed  -n  1~2p''  will  print all the odd-numbered lines in the
202              input stream, and the address 2~5 will match every  fifth  line,
203              starting with the second. (This is an extension.)
204
205       $      Match the last line.
206
207       /regexp/
208              Match lines matching the regular expression regexp.
209
210       \cregexpc
211              Match  lines  matching the regular expression regexp.  The c may
212              be any character.
213
214       GNU sed also supports some special 2-address forms:
215
216       0,addr2
217              Start out in "matched  first  address"  state,  until  addr2  is
218              found.  This is similar to 1,addr2, except that if addr2 matches
219              the very first line of input the 0,addr2 form will be at the end
220              of  its  range,  whereas  the  1,addr2 form will still be at the
221              beginning of its range.
222
223       addr1,+N
224              Will match addr1 and the N lines following addr1.
225
226       addr1,~N
227              Will match addr1 and the lines following addr1  until  the  next
228              line whose input line number is a multiple of N.
229

REGULAR EXPRESSIONS

231       POSIX.2 BREs should be supported, but they aren't completely because of
232       performance problems.  The \n sequence in a regular expression  matches
233       the newline character, and similarly for \a, \t, and other sequences.
234

BUGS

236       E-mail  bug  reports  to  bonzini@gnu.org.  Be sure to include the word
237       ``sed'' somewhere in the ``Subject:'' field.  Also, please include  the
238       output of ``sed --version'' in the body of your report if at all possi‐
239       ble.
240
242       Copyright © 2003 Free Software Foundation, Inc.
243       This is free software; see the source for copying conditions.  There is
244       NO  warranty;  not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
245       PURPOSE, to the extent permitted by law.
246

SEE ALSO

248       awk(1), ed(1), grep(1), tr(1),  perlre(1),  sed.info,  any  of  various
249       books on sed, the sed FAQ (http://sed.sf.net/grabbag/tutorials/sed
250       faq.txt), http://sed.sf.net/grabbag/.
251
252       The full documentation for sed is maintained as a Texinfo manual.  If
253       the info and sed programs are properly installed at your site, the com‐
254       mand
255
256              info sed
257
258       should give you access to the complete manual.
259
260
261
262sed version 4.1.5                  June 2006                            SED(1)
Impressum