2015-10-08 11:15:08 -04:00
|
|
|
.Dd 2015-10-08
|
2015-02-28 07:46:20 -05:00
|
|
|
.Dt SED 1
|
|
|
|
.Os sbase
|
|
|
|
.Sh NAME
|
|
|
|
.Nm sed
|
2015-08-04 11:57:40 -04:00
|
|
|
.Nd stream editor
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Nm
|
|
|
|
.Op Fl nrE
|
|
|
|
.Ar script
|
|
|
|
.Op Ar file ...
|
|
|
|
.Nm
|
|
|
|
.Op Fl nrE
|
|
|
|
.Fl e Ar script
|
|
|
|
.Op Fl e Ar script
|
|
|
|
.Ar ...
|
|
|
|
.Op Fl f Ar scriptfile
|
|
|
|
.Ar ...
|
|
|
|
.Op Ar file ...
|
|
|
|
.Nm
|
|
|
|
.Op Fl nrE
|
|
|
|
.Op Fl e Ar script
|
|
|
|
.Ar ...
|
|
|
|
.Fl f Ar scriptfile
|
|
|
|
.Op Fl f Ar scriptfile
|
|
|
|
.Ar ...
|
|
|
|
.Op Ar file ...
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
.Nm
|
|
|
|
reads line oriented output from
|
|
|
|
.Ar file
|
|
|
|
or stdin, applies the editing commands supplied by
|
|
|
|
.Ar script
|
|
|
|
or
|
|
|
|
.Ar scriptfile
|
|
|
|
and writes the edited stream to stdout.
|
|
|
|
.Sh OPTIONS
|
|
|
|
.Bl -tag -width Ds
|
|
|
|
.It Fl n
|
|
|
|
Suppress default printing at the end of each cycle.
|
|
|
|
.It Fl r E
|
|
|
|
Use extended regular expressions
|
|
|
|
.It Fl e Ar script
|
|
|
|
Append
|
|
|
|
.Ar script
|
|
|
|
to the list of editing commands.
|
|
|
|
.It Fl f Ar scriptfile
|
|
|
|
Append the commands from
|
|
|
|
.Ar scriptfile
|
|
|
|
to the list of editing commands.
|
|
|
|
.El
|
|
|
|
.Sh EXTENDED DESCRIPTION
|
|
|
|
Editing commands take the form
|
|
|
|
.Pp
|
|
|
|
[address[,address]]function
|
|
|
|
.Ss Addresses
|
|
|
|
Addresses are either blank, a positive decimal integer denoting a line
|
|
|
|
number, the character '$' denoting the last line of input, or a regular
|
2020-03-01 17:37:31 -05:00
|
|
|
expression.
|
|
|
|
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.
|
2015-08-04 11:57:40 -04:00
|
|
|
.Ss Functions
|
|
|
|
.Bl -tag -width Ds
|
|
|
|
.It Ar a Op Ar text
|
|
|
|
Append text to output after end of current cycle.
|
|
|
|
.It Ar b Op Ar label
|
2020-03-01 17:37:31 -05:00
|
|
|
Branch to label.
|
|
|
|
If no label is provided branch to end of script.
|
2015-08-04 11:57:40 -04:00
|
|
|
.It Ar c Op Ar text
|
2020-03-01 17:37:31 -05:00
|
|
|
Change.
|
|
|
|
Delete addressed range and output text after end of current cycle.
|
2015-08-04 11:57:40 -04:00
|
|
|
.It Ar d
|
|
|
|
Delete pattern space and begin next cycle.
|
|
|
|
.It Ar D
|
|
|
|
Delete pattern space up to and including first newline and begin new
|
2020-03-01 17:37:31 -05:00
|
|
|
cycle without reading input.
|
|
|
|
If there is no newline, behave like d.
|
2015-08-04 11:57:40 -04:00
|
|
|
.It Ar g
|
2020-03-01 17:37:31 -05:00
|
|
|
Get.
|
|
|
|
Replace the pattern space with the hold space.
|
2015-08-04 11:57:40 -04:00
|
|
|
.It Ar G
|
2020-03-01 17:37:31 -05:00
|
|
|
Get.
|
|
|
|
Append a newline and the hold space to the pattern space.
|
2015-08-04 11:57:40 -04:00
|
|
|
.It Ar h
|
2020-03-01 17:37:31 -05:00
|
|
|
Hold.
|
|
|
|
Replace the hold space with the pattern space.
|
2015-08-04 11:57:40 -04:00
|
|
|
.It Ar H
|
2020-03-01 17:37:31 -05:00
|
|
|
Hold.
|
|
|
|
Append a newline and the pattern space to the hold space.
|
2015-08-04 11:57:40 -04:00
|
|
|
.It Ar i Op Ar text
|
|
|
|
Insert text in output.
|
|
|
|
.It Ar l
|
|
|
|
List? Write the pattern space replacing known non printing characters with
|
2020-03-01 17:37:31 -05:00
|
|
|
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 '$'.
|
2015-08-04 11:57:40 -04:00
|
|
|
.It Ar n
|
2020-03-01 17:37:31 -05:00
|
|
|
Next.
|
|
|
|
Write pattern space (unless
|
2015-08-04 11:57:40 -04:00
|
|
|
.Fl n ) ,
|
2020-03-01 17:37:31 -05:00
|
|
|
read next line into pattern space, and continue current cycle.
|
|
|
|
If there is no next line, quit.
|
2015-08-04 11:57:40 -04:00
|
|
|
.It Ar N
|
2020-03-01 17:37:31 -05:00
|
|
|
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.
|
2015-08-04 11:57:40 -04:00
|
|
|
.It Ar p
|
|
|
|
Print current pattern space.
|
|
|
|
.It Ar P
|
|
|
|
Print current pattern space up to first newline.
|
|
|
|
.It Ar q
|
|
|
|
Quit.
|
|
|
|
.It Ar r file
|
|
|
|
Read file and write contents to output.
|
|
|
|
.It Ar s/re/text/flags
|
2020-03-01 17:37:31 -05:00
|
|
|
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 \\.
|
2015-08-04 11:57:40 -04:00
|
|
|
.Pp
|
|
|
|
Flags are
|
|
|
|
.Bl -tag -width Ds
|
|
|
|
.It Ar n
|
|
|
|
A positive decimal number denoting which match in the pattern space
|
|
|
|
to replace.
|
|
|
|
.It Ar g
|
2020-03-01 17:37:31 -05:00
|
|
|
Global.
|
|
|
|
Replace all matches in the pattern space.
|
2015-08-04 11:57:40 -04:00
|
|
|
.It Ar p
|
|
|
|
Print the pattern if a replacement was made.
|
|
|
|
.It Ar w file
|
|
|
|
Write the pattern space to file if a replacement was made.
|
|
|
|
.El
|
|
|
|
.It Ar t Op Ar label
|
2020-03-01 17:37:31 -05:00
|
|
|
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.
|
2015-08-04 11:57:40 -04:00
|
|
|
.It Ar w file
|
|
|
|
Write pattern space to file.
|
|
|
|
.It Ar x
|
|
|
|
Exchange hold space and pattern space.
|
|
|
|
.It Ar y/set1/set2/
|
|
|
|
Replace each occurrence of a character from set 1 with the corresponding
|
|
|
|
character from set 2.
|
|
|
|
.It Ar :label
|
|
|
|
Create a label for b and t commands.
|
|
|
|
.It Ar =
|
|
|
|
Write current input line number to output.
|
2015-08-04 14:51:40 -04:00
|
|
|
.El
|