Perhaps sed was not meant to be a programming language, but there is a limited
form of flow control. Adding some features common in other languages to sed would
facilitate solving some problems and perhaps make sed more readable. Here are
features I would like to see in an improved sed or a "trans sed".
-
global macros - sed supports macros within a regular expression and within a
substitute command. These are \1 through \9 and are defined by previously placed
pairs of escaped parentheses. A formal global macro definition would reduce the
overall length and size of larger sed scripts.
-
global integer variables would facilitate counting and enumeration of substitutions
within the actual substitution.
-
a way to compare the "hold" and "pattern" spaces and then "branch" equal and not equal
-
the ability to branch on substitution or on no substitution for the substitute
command
-
the ability to branch on match or branch on no match for an "address" (which may
be a regular expression.) This command would immediately follow a pair of
braces.