💾 Archived View for drewdevault.com › cgi-bin › man.sh › 1 › sed captured on 2021-12-03 at 14:04:38.
⬅️ Previous capture (2021-11-30)
-=-=-=-=-=-=-
SED(1P) POSIX Programmer's Manual SED(1P) PROLOG This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME sed -- stream editor SYNOPSIS sed [-n] script [file...] sed [-n] -e script [-e script]... [-f script_file]... [file...] sed [-n] [-e script]... -f script_file [-f script_file]... [file...] DESCRIPTION The sed utility is a stream editor that shall read one or more text files, make editing changes according to a script of editing commands, and write the results to standard output. The script shall be obtained from either the script operand string or a combination of the option-arguments from the -e script and -f script_file options. OPTIONS The sed utility shall conform to the Base Definitions volume of POSIX.1-2017, Section 12.2, Utility Syntax Guidelines, except that the order of presentation of the -e and -f options is significant. The following options shall be supported: -e script Add the editing commands specified by the script option-argument to the end of the script of editing commands. -f script_file Add the editing commands in the file script_file to the end of the script of editing commands. -n Suppress the default output (in which each line, after it is examined for editing, is written to standard output). Only lines explicitly selected for output are written. If any -e or -f options are specified, the script of editing commands shall initially be empty. The commands specified by each -e or -f option shall be added to the script in the order specified. When each addition is made, if the previous addition (if any) was from a -e option, a <newline> shall be inserted before the new addition. The resulting script shall have the same properties as the script operand, described in the OPERANDS section. OPERANDS The following operands shall be supported: file A pathname of a file whose contents are read and edited. If multiple file operands are specified, the named files shall be read in the order specified and the concatenation shall be edited. If no file operands are specified, the standard input shall be used. script A string to be used as the script of editing commands. The application shall not present a script that violates the restrictions of a text file except that the final character need not be a <newline>. STDIN The standard input shall be used if no file operands are specified, and shall be used if a file operand is '-' and the implementation treats the '-' as meaning standard input. Otherwise, the standard input shall not be used. See the INPUT FILES section. INPUT FILES The input files shall be text files. The script_files named by the -f option shall consist of editing commands. ENVIRONMENT VARIABLES The following environment variables shall affect the execution of sed: LANG Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1-2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements within regular expressions. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments and input files), and the behavior of character classes within regular expressions. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. ASYNCHRONOUS EVENTS Default. STDOUT The input files shall be written to standard output, with the editing commands specified in the script applied. If the -n option is specified, only those input lines selected by the script shall be written to standard output. STDERR The standard error shall be used only for diagnostic and warning messages. OUTPUT FILES The output files shall be text files whose formats are dependent on the editing commands given. EXTENDED DESCRIPTION The script shall consist of editing commands of the following form: [address[,address]]function where function represents a single-character command verb from the list in Editing Commands in sed, followed by any applicable arguments. The command can be preceded by <blank> characters and/or <semicolon> characters. The function can be preceded by <blank> characters. These optional characters shall have no effect. In default operation, sed cyclically shall append a line of input, less its terminating <newline> character, into the pattern space. Reading from input shall be skipped if a <newline> was in the pattern space prior to a D command ending the previous cycle. The sed utility shall then apply in sequence all commands whose addresses select that pattern space, until a command starts the next cycle or quits. If no commands explicitly started a new cycle, then at the end of the script the pattern space shall be copied to standard output (except when -n is specified) and the pattern space shall be deleted. Whenever the pattern space is written to standard output or a named file, sed shall immediately follow it with a <newline>. Some of the editing commands use a hold space to save all or part of the pattern space for subsequent retrieval. The pattern and hold spaces shall each be able to hold at least 8192 bytes. Addresses in sed An address is either a decimal number that counts input lines cumulatively across files, a '