Linux Shell Scripting Tutorial (LSST) v1.05r3
Prev
Chapter 6: Learning expressions with ex
Next

Using & as Special replacement character

Try the following command:
:1,$ s/Linux/&-Unix/p
3 substitutions on 3 lines
Rani my sister never uses Linux-Unix

:g/Linux-Unix/p
Linux-Unix is cooool.
Linux-Unix is now 10 years old.
Rani my sister never uses Linux-Unix

This command will replace, target pattern "Linux" with "Linux-Unix". & before - Unix means use "last pattern found" with given pattern, So here last pattern found is "Linux" which is used with given -Unix pattern (Finally constructing "Linux-Unix" substitute for "Linux").
Can you guess the output of this command?
:1,$ s/Linux-Unix/&Linux/p


Prev
Home
Next
Using range of characters in regular expressions
Up
Converting lowercase character to uppercase