sed.1 - sbase - suckless unix tools
(HTM) git clone git://git.suckless.org/sbase
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
sed.1 (4488B)
---
1 .Dd October 8, 2015
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 ...
28 .Sh DESCRIPTION
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
52 .Sh EXTENDED DESCRIPTION
53 Editing commands take the form:
54 .Pp
55 [address[,address]]function
56 .Pp
57 Commands can be separated by ';' or by a new line.
58 .Pp
59 Multiple functions for the specified address (or address-range) can be enclosed
60 in blocks with '{' and '}':
61 .Pp
62 [address[,address]] { function ; function }
63 .Ss Addresses
64 Addresses are either blank, a positive decimal integer denoting a line
65 number, the character '$' denoting the last line of input, or a regular
66 expression (in the format
67 .No / Ns
68 .Ar regexp Ns /).
69 A command with no addresses matches every line, one address matches
70 individual lines, and two addresses matches a range of lines from the
71 first to the second address inclusive.
72 .Pp
73 The character '!' may be appended after the addresses,
74 in which case the function is executed only if the addresses
75 .Em don't
76 match.
77 .Ss Functions
78 .Bl -tag -width Ds
79 .It Ar a Op Ar text
80 Append text to output after end of current cycle.
81 .It Ar b Op Ar label
82 Branch to label.
83 If no label is provided branch to end of script.
84 .It Ar c Op Ar text
85 Change.
86 Delete addressed range and output text after end of current cycle.
87 .It Ar d
88 Delete pattern space and begin next cycle.
89 .It Ar D
90 Delete pattern space up to and including first newline and begin new
91 cycle without reading input.
92 If there is no newline, behave like d.
93 .It Ar g
94 Get.
95 Replace the pattern space with the hold space.
96 .It Ar G
97 Get.
98 Append a newline and the hold space to the pattern space.
99 .It Ar h
100 Hold.
101 Replace the hold space with the pattern space.
102 .It Ar H
103 Hold.
104 Append a newline and the pattern space to the hold space.
105 .It Ar i Op Ar text
106 Insert text in output.
107 .It Ar l
108 List? Write the pattern space replacing known non printing characters with
109 backslash escaped versions (\\\\, \\a, \\b, \\f, \\r, \\t, \\v).
110 Print bad UTF-8 sequences as \\ooo where ooo is a three digit octal
111 number.
112 Mark end of lines with '$'.
113 .It Ar n
114 Next.
115 Write pattern space (unless
116 .Fl n ) ,
117 read next line into pattern space, and continue current cycle.
118 If there is no next line, quit.
119 .It Ar N
120 Next.
121 Read next line, append newline and next line to pattern space, and
122 continue cycle.
123 If there is no next line, quit without printing current pattern space.
124 .It Ar p
125 Print current pattern space.
126 .It Ar P
127 Print current pattern space up to first newline.
128 .It Ar q
129 Quit.
130 .It Ar r file
131 Read file and write contents to output.
132 .It Ar s/re/text/flags
133 Find occurences of regular expression re in the pattern space and
134 replace with text.
135 A '&' in text is replaced with the entire match.
136 A \\d where d is a decimal digit 1-9 is replaced with the corresponding
137 match group from the regular expression.
138 \\n represents a newline in both the regular expression and replacement
139 text.
140 A literal newline in the replacement text must be preceded by a \\.
141 .Pp
142 Flags are
143 .Bl -tag -width Ds
144 .It Ar n
145 A positive decimal number denoting which match in the pattern space
146 to replace.
147 .It Ar g
148 Global.
149 Replace all matches in the pattern space.
150 .It Ar p
151 Print the pattern if a replacement was made.
152 .It Ar w file
153 Write the pattern space to file if a replacement was made.
154 .El
155 .It Ar t Op Ar label
156 Test.
157 Branch to corresponding label if a substitution has been made since the
158 last line was read or last t command was executed.
159 If no label is provided branch to end of script.
160 .It Ar w file
161 Write pattern space to file.
162 .It Ar x
163 Exchange hold space and pattern space.
164 .It Ar y/set1/set2/
165 Replace each occurrence of a character from set 1 with the corresponding
166 character from set 2.
167 .It Ar :label
168 Create a label for b and t commands.
169 .It Ar #comment
170 The comment extends until the next newline.
171 .It Ar =
172 Write current input line number to output.
173 .El