most common, use of sed: substitution. This usage was indeed the original motivation for sed: sed 's/regexp/replacement/g' inputFileName > outputFileName In some versions of sed, the expression must be preceded by -e to indicate that an expression follows. The s stands for substitute, while the g stands for global, which means that all matching occurrences in the line would be replaced. The regular expression (i.e. pattern) to be searched is placed after the first delimiting symbol (slash here) and the replacement follows the second symbol. Slash (/) is the conventional symbol, originating in the character for "search" in ed, but any other could be used to make syntax more readable if it does not occur in the pattern or replacement; this is useful to avoid "leaning toothpick syndrome". The substitution command, which originates in search-and-replace in ed, implements simple parsing and templating. The regexp provides both pattern matching and saving text via sub-expressions, while the replacement can be either literal text, or a format string containing the characters & for "entire match" or the special escape sequences \1 through \9 for the nth saved sub-expression. For example, sed -r "s/(cat|dog)s?/\1s/g" replaces all occurrences of "cat" or "dog" with "cats" or "dogs", without duplicating an existing "s": (cat|dog) is the 1st (and only) saved sub-expression in the regexp, and \1 in the format string substitutes this into the output. Other sed commands Besides substitution, other forms of simple processing are possible, using some 25 sed commands. For example, the following uses the d command to filter out lines that only contain spaces, or only contain the end of line character: sed '/^ *$/d' inputFileName This example uses some of the following regular expression metacharacters (sed supports the full range of regular expressions): The caret (^) matches the beginning of the line. The dollar sign ($) matches the end of the line. The asterisk (*) matches zero or more occurrences of the previous character. The plus (+) matches one or more occurrence(s) of the previous character. The question mark (?) matches zero or one occurrence of the previous character. The dot (.) matches exactly one character. Complex sed constructs are possible, allowing it to serve as a simple, but highly specialized, programming language. Flow of control, for example, can be managed by the use of a label (a colon followed by a string) and the branch instruction b, as well as the