4.4.2 Replacement expressions
For the replacement expression, following characters have special meanings:
For Perl replacement string, $n is used instead of
\n and & has no special meaning.
For example:
$ echo zzz1abc2efg3hij4 | \
sed -e 's/\(1[a-z]*\)[0-9]*\(.*\)$/=&=/'
zzz=1abc2efg3hij4=
$ echo zzz1abc2efg3hij4 | \
sed -e 's/\(1[a-z]*\)[0-9]*\(.*\)$/\2===\1/'
zzzefg3hij4===1abc
$ echo zzz1abc2efg3hij4 | \
perl -pe 's/(1[a-z]*)[0-9]*(.*)$/$2===$1/'
zzzefg3hij4===1abc
$ echo zzz1abc2efg3hij4 | \
perl -pe 's/(1[a-z]*)[0-9]*(.*)$/=&=/'
zzz=&=
Here please pay extra attention to the style of the bracketed
regular expression and how the matched strings are used in the text replacement
process on different tools.
These regular expressions can be used for the cursor movements and the text
replacement actions in the editors too.
Please read all the related manual pages to learn these commands.