SEARCH
NEW RPMS
DIRECTORIES
ABOUT
FAQ
VARIOUS
BLOG
DONATE


YUM REPOSITORY

 
 

SED

Section: User Commands (1)
Index 

NAME

sed - stream editor 

SYNOPSIS

sed[-n][-g][-escript][-fsfile][file ...] 

DESCRIPTION

Sedcopies the namedfiles(standard input default) to the standard output,edited according to a script of commands.The-foption causes the script to be taken from filesfile;these options accumulate.If there is just one-eoption and no-f's,the flag-emay be omitted.The-noption suppresses the default output;-gcauses all substitutions to be global, as if suffixedg.

A script consists of editing commands, one per line,of the following form:

[address [, address] ] function [argument ...]

In normal operationsedcyclically copies a line of input into apattern space(unless there is something left aftera command),applies in sequenceall commands whoseaddressesselect that pattern space,and at the end of the script copies the pattern spaceto the standard output (except under-n)and deletes the pattern space.

Anaddressis either a decimal number that countsinput lines cumulatively across files, a thataddresses the last line of input, or a context address,/regular-expression/,in the style ofregexp(7),with the added convention thatmatches anewline embedded in the pattern space.

A command line with no addresses selects every pattern space.

A command line withone address selects each pattern space that matches the address.

A command line withtwo addresses selects the inclusive range from the firstpattern space that matches the first address throughthe next pattern space that matchesthe second.(If the second address is a number less than or equalto the line number first selected, only oneline is selected.)Thereafter the process is repeated, looking again for thefirst address.

Editing commands can be applied to non-selected patternspaces by use of the negation function (below).

An argument denotedtextconsists of one or more lines,all but the last of which end with to hide thenewline.Backslashes in text are treated like backslashesin the replacement string of an command,and may be used to protect initial blanks and tabsagainst the stripping that is done onevery script line.

An argument denotedrfileorwfilemust terminate the commandline and must be preceded by exactly one blank.Eachwfileis created before processing begins.There can be at most 120 distinctwfilearguments.

a\

text
Append.Placetexton the output beforereading the next input line.
b label
Branch to the :command bearing thelabel.Iflabelis empty, branch to the end of the script.
c\

text
Change.Delete the pattern space.With 0 or 1 address or at the end of a 2-address range, placetexton the output.Start the next cycle.
d
Delete the pattern space.Start the next cycle.
D
Delete the initial segment of thepattern space through the first newline.Start the next cycle.
g
Replace the contents of the pattern spaceby the contents of the hold space.
G
Append the contents of the hold space to the pattern space.
h
Replace the contents of the hold space by the contents of the pattern space.
H
Append the contents of the pattern space to the hold space.
i\

text
Insert.Placetexton the standard output.
n
Copy the pattern space to the standard output.Replace the pattern space with the next line of input.
N
Append the next line of input to the pattern spacewith an embedded newline.(The current line number changes.)
p
Print.Copy the pattern space to the standard output.
P
Copy the initial segment of the pattern space throughthe first newline to the standard output.
q
Quit.Branch to the end of the script.Do not start a new cycle.
r rfile
Read the contents ofrfile.Place them on the output before readingthe next input line.
s/regular-expression/replacement/flags
Substitute thereplacementstring for instances of theregular-expressionin the pattern space.Any character may be used instead of For a fuller description seeregexp(7).Flagsis zero or more of
g
Global.Substitute for all non-overlapping instances of theregular expressionrather than just thefirst one.
p
Print the pattern space if a replacement was made.
w wfile
Write.Append the pattern space towfileif a replacementwas made.
t label
Test.Branch to the command bearing thelabelif anysubstitutions have been made since the most recentreading of an input line or execution of a Iflabelis empty, branch to the end of the script.
w
wfile
Write.Append the pattern space towfile.
x
Exchange the contents of the pattern and hold spaces.
y/string1/string2/
Transform.Replace all occurrences of characters instring1with the corresponding character instring2.The lengths ofstring1andstring2must be equal.
!function
Don't.Apply thefunction(or group, iffunctionis only to linesnotselected by the address(es).
: label
This command does nothing; it bears alabelfor band tcommands to branch to.
=
Place the current line number on the standard output as a line.
{
Execute the following commands through a matching only when the pattern space is selected.
An empty command is ignored.
 

EXAMPLES

sed 10q file
Print the first 10 lines of the file.
sed '/^$/d'
Delete empty lines from standard input.
sed 's/UNIX/& system/g'
Replace every instance of by

sed 's/ *$//  drop trailing blanks
/^$/d                   drop empty lines
s/ */\         replace blanks by newlines
/g/^$/d' chapter*

Print the files chapter1,chapter2,etc. one word to a line.

nroff -ms manuscript | sed '${        /^$/p           if last line of file is empty, print it
}//N                     if current line is empty, append next line
/^\n$/D'                if two lines are empty, delete the first

Delete all but one of each group of empty lines from aformatted manuscript.
 

SOURCE

/src/cmd/sed.c 

SEE ALSO

ed(1),grep(1),awk(1),lex(1),sam(1),regexp(7)
L. E. McMahon,`SED --- A Non-interactive Text Editor',Unix Research System Programmer's Manual, Volume 2. 

BUGS

If input is from a pipe, buffering may consumecharacters beyond a line on which a command is executed.


 

Index

NAME
SYNOPSIS
DESCRIPTION
EXAMPLES
SOURCE
SEE ALSO
BUGS

This document was created byman2html,using the manual pages.