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