public final class Sed extends Object
NAME
sed - stream editor for filtering and transforming text
SYNOPSIS
sed <args> | |
sed <script> | |
sed <regexp> <replacement> | |
sed <regexp> <replacement> <occurrence> | |
sed [-ngplIsaicdy] <regexp> | |
sed [-ngplIsaicdy] <string1> <string2> | |
sed [-ngplIsaicdy] <string1> <string2> <occurrence> |
See Sed.Interface
for the corresponding command signature methods.
DESCRIPTION
Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sed's ability to filter text in a pipeline which particularly distinguishes it from other types of editors.
Some examples:
input day into sed("s/day/night/") This will output "night"
input "day and night" into sed("s/\\sand\\s/-to-/") This will output "day-to-night"(Note the use of \s whitespace character).
Pattern
documentation.
Options
The following options are supported:
-n | --quiet | 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. | |||
-g | --global | Globally substitute for all non-overlapping instances of the regexp
rather than just the first one.
(This option is ignored if the occurrence operand is specified). | |||
-p | --print | Write the matched line to standard output. | |||
-l | --lineNumber | Writes the current line number on a separate line to the standard output. | |||
-I | --ignoreCase | Use case insensitive pattern matching. | |||
-s | --substitute | Substitutes the replacement string for instances of the regexp in
the matched line.
The characters "$0" appearing in the replacement are replaced by the line matching the regexp. The characters "$n", where n is a digit other than zero, are replaced by the text matched by the corresponding backreference expression (aka group). The special meaning of "$n" in this context can be suppressed by preceding it by a backslash. A line can be split by substituting a newline ('\n') into it. A substitution is considered to have been performed even if the replacement string is identical to the string that it replaces. | |||
-a | --append | Append string2 as a separate line after the matched line. | |||
-i | --insert | Insert string2 as a separate line before the matched line. | |||
-c | --change | Write string2 as a separate line instead of the matched line. | |||
-d | --delete | Delete the matched line. | |||
-y | --translate | Replace all occurrences of characters in string1 with the corresponding characters in string2. If the number of characters in the two strings are not equal, or if any of the characters in string1 appear more than once, the results are undefined. |
OPERANDS
The following operands are supported:
<script> | : | String | Sed script as one string, such as "s/original/replacement/g". | ||
<regexp> | : | String | Regular expression matched against a line. | ||
<string1> | : | String | Regular expression matched against a line for all commands except for command y where string1 contains the source characters for the translation. | ||
<replacement> | : | String | Replacement string for substitute command. The characters "$0" appearing in the replacement are replaced by the line matching the regexp. The characters "$n", where n is a digit other than zero, are replaced by the text matched by the corresponding backreference expression (aka group). The special meaning of "$n" in this context can be suppressed by preceding it by a backslash. | ||
<string2> | : | String | Replacement string for substitute command s; appended, inserted or
changed text for a, i and c command; destination characters for
translate command y; ignored by all other commands.
If string2 is a replacement string for the substitute command: the characters "$0" appearing in the replacement are replaced by the line matching the regexp; the characters "$n", where n is a digit other than zero, are replaced by the text matched by the corresponding backreference expression (aka group). The special meaning of "$n" in this context can be suppressed by preceding it by a backslash. (This operand only applies to the commands s, a, i, c and y and is ignored by all other commands). | ||
<occurrence> | : | int... | Substitute for the given occurrences only of the regexp found within
the matched string; the occurrence indices are one-based. If empty
or omitted, all occurrences are substituted.
(This operand only applies to the substitute command and is ignored by all other commands). | ||
<args> | : | String... | String arguments defining the options and operands for the command. Options can be specified by acronym (with a leading dash "-") or by long name (with two leading dashes "--"). Operands other than the default "--script" operand have to be prefixed with the operand name (e.g. "--occurrence" for subsequent occurrence indices). | ||
<options> | : | SedOptions | Sed options and commands |
Modifier and Type | Class and Description |
---|---|
static interface |
Sed.Interface<R>
Interface defining all method signatures for the "sed" command.
|
Modifier and Type | Field and Description |
---|---|
static SedFactory |
Factory
Singleton
factory instance for the "sed" command. |
static String |
NAME
The "sed" command name.
|
static SedOptionSets |
Options
|
public static final String NAME
public static final SedOptionSets Options
n
, g
, p
, l
, I
, s
, a
, i
, c
, d
, y
.
-n | --quiet | 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. | |||
-g | --global | Globally substitute for all non-overlapping instances of the regexp
rather than just the first one.
(This option is ignored if the occurrence operand is specified). | |||
-p | --print | Write the matched line to standard output. | |||
-l | --lineNumber | Writes the current line number on a separate line to the standard output. | |||
-I | --ignoreCase | Use case insensitive pattern matching. | |||
-s | --substitute | Substitutes the replacement string for instances of the regexp in
the matched line.
The characters "$0" appearing in the replacement are replaced by the line matching the regexp. The characters "$n", where n is a digit other than zero, are replaced by the text matched by the corresponding backreference expression (aka group). The special meaning of "$n" in this context can be suppressed by preceding it by a backslash. A line can be split by substituting a newline ('\n') into it. A substitution is considered to have been performed even if the replacement string is identical to the string that it replaces. | |||
-a | --append | Append string2 as a separate line after the matched line. | |||
-i | --insert | Insert string2 as a separate line before the matched line. | |||
-c | --change | Write string2 as a separate line instead of the matched line. | |||
-d | --delete | Delete the matched line. | |||
-y | --translate | Replace all occurrences of characters in string1 with the corresponding characters in string2. If the number of characters in the two strings are not equal, or if any of the characters in string1 appear more than once, the results are undefined. |
public static final SedFactory Factory
factory
instance for the "sed" command.Copyright © 2024. All rights reserved.