|
|
1.1 ! root 1: .\" @(#)sed.1 6.2 (Berkeley) 9/30/87 ! 2: .\" ! 3: .TH SED 1 "September 30, 1987" ! 4: .AT 3 ! 5: .SH NAME ! 6: sed \- stream editor ! 7: .SH SYNOPSIS ! 8: .B sed ! 9: [ ! 10: .B \-n ! 11: ] ! 12: [ ! 13: .B \-e ! 14: script ] [ ! 15: .B \-f ! 16: sfile ] [ file ] ... ! 17: .SH DESCRIPTION ! 18: .I Sed ! 19: copies the named ! 20: .I files ! 21: (standard input default) to the standard output, ! 22: edited according to a script of commands. ! 23: The ! 24: .B \-f ! 25: option causes the script to be taken from file ! 26: .IR sfile ; ! 27: these options accumulate. ! 28: If there is just one ! 29: .B \-e ! 30: option and no ! 31: .BR \-f 's, ! 32: the flag ! 33: .B \-e ! 34: may be omitted. ! 35: The ! 36: .B \-n ! 37: option suppresses the default output. ! 38: .PP ! 39: A script consists of editing commands, one per line, ! 40: of the following form: ! 41: .IP ! 42: [address [, address] ] function [arguments] ! 43: .PP ! 44: In normal operation ! 45: .I sed ! 46: cyclically copies a line of input into a ! 47: .I pattern space ! 48: (unless there is something left after ! 49: a `D' command), ! 50: applies in sequence ! 51: all commands whose ! 52: .I addresses ! 53: select that pattern space, ! 54: and at the end of the script copies the pattern space ! 55: to the standard output (except under ! 56: .BR \-n ) ! 57: and deletes the pattern space. ! 58: .PP ! 59: An ! 60: .I address ! 61: is either a decimal number that counts ! 62: input lines cumulatively across files, a `$' that ! 63: addresses the last line of input, or a context address, ! 64: `/regular expression/', in the style of ! 65: .IR ed (1) ! 66: modified thus: ! 67: .IP ! 68: The escape sequence `\en' matches a ! 69: newline embedded in the pattern space. ! 70: .PP ! 71: A command line with no addresses selects every pattern space. ! 72: .PP ! 73: A command line with ! 74: one address selects each pattern space that matches the address. ! 75: .PP ! 76: A command line with ! 77: two addresses selects the inclusive range from the first ! 78: pattern space that matches the first address through ! 79: the next pattern space that matches ! 80: the second. ! 81: (If the second address is a number less than or equal ! 82: to the line number first selected, only one ! 83: line is selected.) ! 84: Thereafter the process is repeated, looking again for the ! 85: first address. ! 86: .PP ! 87: Editing commands can be applied only to non-selected pattern ! 88: spaces by use of the negation function `!' (below). ! 89: .PP ! 90: In the following list of functions the ! 91: maximum number of permissible addresses ! 92: for each function is indicated in parentheses. ! 93: .PP ! 94: An argument denoted ! 95: .I text ! 96: consists of one or more lines, ! 97: all but the last of which end with `\e' to hide the ! 98: newline. ! 99: Backslashes in text are treated like backslashes ! 100: in the replacement string of an `s' command, ! 101: and may be used to protect initial blanks and tabs ! 102: against the stripping that is done on ! 103: every script line. ! 104: .PP ! 105: An argument denoted ! 106: .I rfile ! 107: or ! 108: .I wfile ! 109: must terminate the command ! 110: line and must be preceded by exactly one blank. ! 111: Each ! 112: .I wfile ! 113: is created before processing begins. ! 114: There can be at most 10 distinct ! 115: .I wfile ! 116: arguments. ! 117: .TP ! 118: (1)\|a\e ! 119: .br ! 120: .ns ! 121: .TP ! 122: .I text ! 123: .br ! 124: Append. ! 125: Place ! 126: .I text ! 127: on the output before ! 128: reading the next input line. ! 129: .TP ! 130: .RI (2)\|b " label" ! 131: Branch to the `:' command bearing the ! 132: .IR label . ! 133: If ! 134: .I label ! 135: is empty, branch to the end of the script. ! 136: .TP ! 137: (2)\|c\e ! 138: .br ! 139: .ns ! 140: .TP ! 141: .I text ! 142: .br ! 143: Change. ! 144: Delete the pattern space. ! 145: With 0 or 1 address or at the end of a 2-address range, place ! 146: .I text ! 147: on the output. ! 148: Start the next cycle. ! 149: .TP ! 150: (2)\|d ! 151: Delete the pattern space. ! 152: Start the next cycle. ! 153: .TP ! 154: (2)\|D ! 155: Delete the initial segment of the ! 156: pattern space through the first newline. ! 157: Start the next cycle. ! 158: .TP ! 159: (2)\|g ! 160: Replace the contents of the pattern space ! 161: by the contents of the hold space. ! 162: .TP ! 163: (2)\|G ! 164: Append the contents of the hold space to the pattern space. ! 165: .TP ! 166: (2)\|h ! 167: Replace the contents of the hold space by the contents of the pattern space. ! 168: .TP ! 169: (2)\|H ! 170: Append the contents of the pattern space to the hold space. ! 171: .TP ! 172: (1)\|i\e ! 173: .br ! 174: .ns ! 175: .TP ! 176: .I text ! 177: .br ! 178: Insert. ! 179: Place ! 180: .I text ! 181: on the standard output. ! 182: .TP ! 183: (2)\|n ! 184: Copy the pattern space to the standard output. ! 185: Replace the pattern space with the next line of input. ! 186: .TP ! 187: (2)\|N ! 188: Append the next line of input to the pattern space ! 189: with an embedded newline. ! 190: (The current line number changes.) ! 191: .TP ! 192: (2)\|p ! 193: Print. ! 194: Copy the pattern space to the standard output. ! 195: .TP ! 196: (2)\|P ! 197: Copy the initial segment of the pattern space through ! 198: the first newline to the standard output. ! 199: .TP ! 200: (1)\|q ! 201: Quit. ! 202: Branch to the end of the script. ! 203: Do not start a new cycle. ! 204: .TP ! 205: .RI (2)\|r " rfile" ! 206: Read the contents of ! 207: .IR rfile . ! 208: Place them on the output before reading ! 209: the next input line. ! 210: .TP ! 211: .RI (2)\|s /regular\ expression/replacement/flags ! 212: Substitute the ! 213: .I replacement ! 214: string for instances of the ! 215: .I regular expression ! 216: in the pattern space. ! 217: Any character may be used instead of `/'. ! 218: For a fuller description see ! 219: .IR ed (1). ! 220: .I Flags ! 221: is zero or more of ! 222: .RS ! 223: .TP ! 224: g ! 225: Global. ! 226: Substitute for all nonoverlapping instances of the ! 227: .I regular expression ! 228: rather than just the ! 229: first one. ! 230: .TP ! 231: p ! 232: Print the pattern space if a replacement was made. ! 233: .TP ! 234: .RI w " wfile" ! 235: Write. ! 236: Append the pattern space to ! 237: .I wfile ! 238: if a replacement ! 239: was made. ! 240: .RE ! 241: .TP ! 242: .RI (2)\|t " label" ! 243: Test. ! 244: Branch to the `:' command bearing the ! 245: .I label ! 246: if any ! 247: substitutions have been made since the most recent ! 248: reading of an input line or execution of a `t'. ! 249: If ! 250: .I label ! 251: is empty, branch to the end of the script. ! 252: .TP ! 253: .RI (2)\|w " wfile" ! 254: Write. ! 255: Append the pattern space to ! 256: .IR wfile . ! 257: .TP ! 258: .RI (2)\|x ! 259: Exchange the contents of the pattern and hold spaces. ! 260: .TP ! 261: .RI (2)\|y /string1/string2/ ! 262: Transform. ! 263: Replace all occurrences of characters in ! 264: .I string1 ! 265: with the corresponding character in ! 266: .I string2. ! 267: The lengths of ! 268: .I ! 269: string1 ! 270: and ! 271: .I string2 ! 272: must be equal. ! 273: .TP ! 274: .RI (2)! " function" ! 275: Don't. ! 276: Apply the ! 277: .I function ! 278: (or group, if ! 279: .I function ! 280: is `{') only to lines ! 281: .I not ! 282: selected by the address(es). ! 283: .TP ! 284: .RI (0)\|: " label" ! 285: This command does nothing; it bears a ! 286: .I label ! 287: for `b' and `t' commands to branch to. ! 288: .TP ! 289: (1)\|= ! 290: Place the current line number on the standard output as a line. ! 291: .TP ! 292: (2)\|{ ! 293: Execute the following commands through a matching `}' ! 294: only when the pattern space is selected. ! 295: .TP ! 296: (0)\| ! 297: An empty command is ignored. ! 298: .TP ! 299: (0)\|# ! 300: If a \fI#\fP appears as the first character on a line of a script, ! 301: then that entire line is treated as a comment, with one exception. ! 302: If the first line of the script starts with the characters ``\fI#\fPn'', ! 303: then the default output will be suppressed. The rest of the line after ! 304: ``\fI#\fPn'' will also be ignored. A script file must contain at least one ! 305: non-comment line. ! 306: .SH SEE ALSO ! 307: ed(1), grep(1), awk(1), lex(1)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.