sed: Extended Commands
1
1 3.7 Commands Specific to GNU 'sed'
1 ==================================
1
1 These commands are specific to GNU 'sed', so you must use them with care
1 and only when you are sure that hindering portability is not evil. They
1 allow you to check for GNU 'sed' extensions or to do tasks that are
1 required quite often, yet are unsupported by standard 'sed's.
1
1 'e [COMMAND]'
1 This command allows one to pipe input from a shell command into
1 pattern space. Without parameters, the 'e' command executes the
1 command that is found in pattern space and replaces the pattern
1 space with the output; a trailing newline is suppressed.
1
1 If a parameter is specified, instead, the 'e' command interprets it
1 as a command and sends its output to the output stream. The
1 command can run across multiple lines, all but the last ending with
1 a back-slash.
1
1 In both cases, the results are undefined if the command to be
1 executed contains a NUL character.
1
1 Note that, unlike the 'r' command, the output of the command will
1 be printed immediately; the 'r' command instead delays the output
1 to the end of the current cycle.
1
1 'F'
1 Print out the file name of the current input file (with a trailing
1 newline).
1
1 'Q [EXIT-CODE]'
1 This command accepts only one address.
1
1 This command is the same as 'q', but will not print the contents of
1 pattern space. Like 'q', it provides the ability to return an exit
1 code to the caller.
1
1 This command can be useful because the only alternative ways to
1 accomplish this apparently trivial function are to use the '-n'
1 option (which can unnecessarily complicate your script) or
1 resorting to the following snippet, which wastes time by reading
1 the whole file without any visible effect:
1
1 :eat
1 $d Quit silently on the last line
1 N Read another line, silently
1 g Overwrite pattern space each time to save memory
1 b eat
1
1 'R FILENAME'
1 Queue a line of FILENAME to be read and inserted into the output
1 stream at the end of the current cycle, or when the next input line
1 is read. Note that if FILENAME cannot be read, or if its end is
1 reached, no line is appended, without any error indication.
1
1 As with the 'r' command, the special value '/dev/stdin' is
1 supported for the file name, which reads a line from the standard
1 input.
1
1 'T LABEL'
1 Branch to LABEL only if there have been no successful
1 's'ubstitutions since the last input line was read or conditional
1 branch was taken. The LABEL may be omitted, in which case the next
1 cycle is started.
1
1 'v VERSION'
1 This command does nothing, but makes 'sed' fail if GNU 'sed'
1 extensions are not supported, simply because other versions of
1 'sed' do not implement it. In addition, you can specify the
1 version of 'sed' that your script requires, such as '4.0.5'. The
1 default is '4.0' because that is the first version that implemented
1 this command.
1
1 This command enables all GNU extensions even if 'POSIXLY_CORRECT'
1 is set in the environment.
1
1 'W FILENAME'
1 Write to the given filename the portion of the pattern space up to
1 the first newline. Everything said under the 'w' command about
1 file handling holds here too.
1
1 'z'
1 This command empties the content of pattern space. It is usually
1 the same as 's/.*//', but is more efficient and works in the
1 presence of invalid multibyte sequences in the input stream. POSIX
1 mandates that such sequences are _not_ matched by '.', so that
1 there is no portable way to clear 'sed''s buffers in the middle of
1 the script in most multibyte locales (including UTF-8 locales).
1