Annotation of researchv10dc/man/adm/man1/sed.1, revision 1.1.1.1

1.1       root        1: .TH SED 1
                      2: .CT 1 files editor
                      3: .SH NAME
                      4: sed \- stream editor
                      5: .SH SYNOPSIS
                      6: .B sed
                      7: [
                      8: .B -n
                      9: ]
                     10: [
                     11: .B -e
                     12: .I script
                     13: ]
                     14: [
                     15: .B -f
                     16: .I sfile
                     17: ]
                     18: [
                     19: .I file ...
                     20: ]
                     21: .SH DESCRIPTION
                     22: .I Sed
                     23: copies the named
                     24: .I files
                     25: (standard input default) to the standard output,
                     26: edited according to a script of commands.
                     27: The
                     28: .B -f
                     29: option causes the script to be taken from file
                     30: .IR sfile ;
                     31: these options accumulate.
                     32: If there is just one
                     33: .B -e
                     34: option and no
                     35: .BR -f 's,
                     36: the flag
                     37: .B -e
                     38: may be omitted.
                     39: The
                     40: .B -n
                     41: option suppresses the default output.
                     42: .PP
                     43: A script consists of editing commands, one per line,
                     44: of the following form:
                     45: .IP
                     46: [\fIaddress\fR [\f5,\fI address\fR] ] \fIfunction\fR [\fIargument\fR ...]
                     47: .PP
                     48: In normal operation
                     49: .I sed
                     50: cyclically copies a line of input into a
                     51: .I pattern space
                     52: (unless there is something left after
                     53: a 
                     54: .L D
                     55: command),
                     56: applies in sequence
                     57: all commands whose
                     58: .I addresses
                     59: select that pattern space,
                     60: and at the end of the script copies the pattern space
                     61: to the standard output (except under
                     62: .BR -n )
                     63: and deletes the pattern space.
                     64: .PP
                     65: An
                     66: .I address
                     67: is either a decimal number that counts
                     68: input lines cumulatively across files, a 
                     69: .L $
                     70: that
                     71: addresses the last line of input, or a context address,
                     72: .BI / regular-expression / ,
                     73: in the style of
                     74: .IR ed (1),
                     75: with the added convention that
                     76: .L \en
                     77: matches a
                     78: newline embedded in the pattern space.
                     79: .PP
                     80: A command line with no addresses selects every pattern space.
                     81: .PP
                     82: A command line with
                     83: one address selects each pattern space that matches the address.
                     84: .PP
                     85: A command line with
                     86: two addresses selects the inclusive range from the first
                     87: pattern space that matches the first address through
                     88: the next pattern space that matches
                     89: the second.
                     90: (If the second address is a number less than or equal
                     91: to the line number first selected, only one
                     92: line is selected.)
                     93: Thereafter the process is repeated, looking again for the
                     94: first address.
                     95: .PP
                     96: Editing commands can be applied to non-selected pattern
                     97: spaces by use of the negation function 
                     98: .L !
                     99: (below).
                    100: .PP
                    101: In the following list of functions the
                    102: maximum number of permissible addresses
                    103: for each function is indicated in parentheses.
                    104: .PP
                    105: An argument denoted
                    106: .I text
                    107: consists of one or more lines,
                    108: all but the last of which end with 
                    109: .L \e
                    110: to hide the
                    111: newline.
                    112: Backslashes in text are treated like backslashes
                    113: in the replacement string of an 
                    114: .L s
                    115: command,
                    116: and may be used to protect initial blanks and tabs
                    117: against the stripping that is done on
                    118: every script line.
                    119: .PP
                    120: An argument denoted
                    121: .I rfile
                    122: or
                    123: .I wfile
                    124: must terminate the command
                    125: line and must be preceded by exactly one blank.
                    126: Each
                    127: .I wfile
                    128: is created before processing begins.
                    129: There can be at most 120 distinct
                    130: .I wfile
                    131: arguments.
                    132: .TP
                    133: .RB (1) \|a\e
                    134: .br
                    135: .ns
                    136: .TP
                    137: .I text
                    138: Append.
                    139: Place
                    140: .I text
                    141: on the output before
                    142: reading the next input line.
                    143: .HP
                    144: .RB (2) \|b
                    145: .I label
                    146: .br
                    147: Branch to the 
                    148: .B :
                    149: command bearing the
                    150: .I label.
                    151: If
                    152: .I label
                    153: is empty, branch to the end of the script.
                    154: .TP
                    155: .RB (2) \|c\e
                    156: .br
                    157: .ns
                    158: .TP
                    159: .I text
                    160: Change.
                    161: Delete the pattern space.
                    162: With 0 or 1 address or at the end of a 2-address range, place
                    163: .I text
                    164: on the output.
                    165: Start the next cycle.
                    166: .TP
                    167: .RB (2) \|d
                    168: Delete the pattern space.
                    169: Start the next cycle.
                    170: .TP
                    171: .RB (2) \|D
                    172: Delete the initial segment of the
                    173: pattern space through the first newline.
                    174: Start the next cycle.
                    175: .TP
                    176: .RB (2) \|g
                    177: Replace the contents of the pattern space
                    178: by the contents of the hold space.
                    179: .TP
                    180: .RB (2) \|G
                    181: Append the contents of the hold space to the pattern space.
                    182: .TP
                    183: .RB (2) \|h
                    184: Replace the contents of the hold space by the contents of the pattern space.
                    185: .TP
                    186: .RB (2) \|H
                    187: Append the contents of the pattern space to the hold space.
                    188: .TP
                    189: .RB (1) \|i\e
                    190: .br
                    191: .ns
                    192: .TP
                    193: .I text
                    194: Insert.
                    195: Place
                    196: .I text
                    197: on the standard output.
                    198: .TP
                    199: .RB (2) \|n
                    200: Copy the pattern space to the standard output.
                    201: Replace the pattern space with the next line of input.
                    202: .TP
                    203: .RB (2) \|N
                    204: Append the next line of input to the pattern space
                    205: with an embedded newline.
                    206: (The current line number changes.)
                    207: .TP
                    208: .RB (2) \|p
                    209: Print.
                    210: Copy the pattern space to the standard output.
                    211: .TP
                    212: .RB (2) \|P
                    213: Copy the initial segment of the pattern space through
                    214: the first newline to the standard output.
                    215: .TP
                    216: .RB (1) \|q
                    217: Quit.
                    218: Branch to the end of the script.
                    219: Do not start a new cycle.
                    220: .HP
                    221: .RB (2) \|r 
                    222: .I rfile
                    223: .br
                    224: Read the contents of
                    225: .IR rfile .
                    226: Place them on the output before reading
                    227: the next input line.
                    228: .TP
                    229: .RB (2) \|s/\fIregular-expression\fP/\fIreplacement\fP/\fIflags
                    230: Substitute the
                    231: .I replacement
                    232: string for instances of the
                    233: .I regular-expression
                    234: in the pattern space.
                    235: Any character may be used instead of 
                    236: .LR / .
                    237: For a fuller description see
                    238: .IR ed (1);
                    239: although unlike
                    240: .I ed ,
                    241: the trailing
                    242: .B /
                    243: .I must
                    244: be supplied.
                    245: .I Flags
                    246: is zero or more of
                    247: .RS
                    248: .TP
                    249: .B g
                    250: Global.
                    251: Substitute for all non-overlapping instances of the
                    252: .I regular expression
                    253: rather than just the
                    254: first one.
                    255: .TP
                    256: .B p
                    257: Print the pattern space if a replacement was made.
                    258: .TP
                    259: .BI w " wfile"
                    260: Write.
                    261: Append the pattern space to
                    262: .I wfile
                    263: if a replacement
                    264: was made.
                    265: .RE
                    266: .HP
                    267: .RB (2) \|t
                    268: .I label
                    269: .br
                    270: Test.
                    271: Branch to the 
                    272: .L :
                    273: command bearing the
                    274: .I label
                    275: if any
                    276: substitutions have been made since the most recent
                    277: reading of an input line or execution of a 
                    278: .LR t .
                    279: If
                    280: .I label
                    281: is empty, branch to the end of the script.
                    282: .TP
                    283: .RB (2) \|w
                    284: .I wfile
                    285: .br
                    286: Write.
                    287: Append the pattern space to
                    288: .I wfile.
                    289: .TP
                    290: .RB (2) \|x
                    291: Exchange the contents of the pattern and hold spaces.
                    292: .TP
                    293: .RB (2) \|y/\fIstring1\fP/\fIstring2\fP/
                    294: Transform.
                    295: Replace all occurrences of characters in
                    296: .I string1
                    297: with the corresponding character in
                    298: .I string2.
                    299: The lengths of
                    300: .I
                    301: string1
                    302: and
                    303: .I string2
                    304: must be equal.
                    305: .HP
                    306: .RB (2) !
                    307: .I function
                    308: .br
                    309: Don't.
                    310: Apply the
                    311: .I function
                    312: (or group, if
                    313: .I function
                    314: is 
                    315: .LR { )
                    316: only to lines
                    317: .I not
                    318: selected by the address(es).
                    319: .HP
                    320: .RB (0) \|:
                    321: .I label
                    322: .br
                    323: This command does nothing; it bears a
                    324: .I label
                    325: for 
                    326: .B b
                    327: and 
                    328: .B t
                    329: commands to branch to.
                    330: .TP
                    331: .RB (1) \|=
                    332: Place the current line number on the standard output as a line.
                    333: .TP
                    334: .RB (2) \|{
                    335: Execute the following commands through a matching 
                    336: .L }
                    337: only when the pattern space is selected.
                    338: .TP
                    339: .RB (0) \|
                    340: An empty command is ignored.
                    341: .ne 4
                    342: .SH EXAMPLES
                    343: .TP
                    344: .B sed 10q file
                    345: Print the first 10 lines of the file.
                    346: .TP
                    347: .B sed '/^$/d'
                    348: Delete empty lines from standard input.
                    349: .TP
                    350: .B sed 's/UNIX/& system/g'
                    351: Replace every instance of 
                    352: .L UNIX
                    353: by
                    354: .LR "UNIX system" .
                    355: .PP
                    356: .EX
                    357: sed 's/ *$//   \fRdrop trailing blanks\fP
                    358: /^$/d                  \fRdrop empty lines\fP
                    359: s/  */\e               \fRreplace blanks by newlines\fP
                    360: /g
                    361: /^$/d' chapter*
                    362: .EE
                    363: .ns
                    364: .IP
                    365: Print the files 
                    366: .BR chapter1 ,
                    367: .BR chapter2 ,
                    368: etc. one word to a line.
                    369: .PP
                    370: .EX
                    371: nroff -ms manuscript | sed '
                    372: ${
                    373:        /^$/p           \fRif last line of file is empty, print it\fP
                    374: }
                    375: //N                    \fRif current line is empty, append next line\fP
                    376: /^\en$/D'              \fRif two lines are empty, delete the first\fP
                    377: .EE
                    378: .ns
                    379: .IP
                    380: Delete all but one of each group of empty lines from a
                    381: formatted manuscript.
                    382: .PP
                    383: .EX
                    384: ls /usr/* | sed '
                    385: /^$/d                  \fRdelete empty lines\fP
                    386: /^[/].*:$/{            \fRlook for lines like \fP/usr/lem:
                    387:        s/:$/\e//       \fRreplace \fP:\fR by \fP/
                    388:        h               \fRhold directory name\fP
                    389:        d               \fRdon't print; get next line\fP
                    390: }
                    391: G                      \fRappend held directory name\fP
                    392: s/\e(.*\e)\en\e(.*\e)/\e2\e1/' \fRexchange file and directory\fP
                    393: .EE
                    394: .ns
                    395: .IP
                    396: List all files in user directories, as
                    397: .B ls -d /usr/*/* 
                    398: would do if it didn't cause argument list overflow.
                    399: .SH SEE ALSO
                    400: .IR ed (1), 
                    401: .IR gre (1), 
                    402: .IR awk (1), 
                    403: .IR lex (1), 
                    404: .IR cut (1), 
                    405: .IR split (1), 
                    406: .IR sam (9.1)
                    407: .br
                    408: L. E. McMahon,
                    409: `SED \(em A Non-interactive Text Editor',
                    410: this manual, Volume 2.
                    411: .SH BUGS
                    412: If input is from a pipe, buffering may consume
                    413: characters beyond a line on which a 
                    414: .L q
                    415: command is executed.

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.