Linux Shell Scripting Tutorial (LSST) v1.05r3 | ||
Chapter 6: Learning expressions with ex | ||
|
Try the following command
:1,$ s/[a-z]/\u &/g
Above command can be explained as follows:
Command | Explanation |
1,$ | Line Address location is all i.e. find all lines for following pattern |
s | Substitute command |
/[a-z]/ | Find all lowercase letter - Target |
\u&/ | Substitute to Uppercase. \u& means substitute last patter (&) matched with its UPPERCASE replacement (\u) Note: Use \l (small L) for lowercase character. |
g | Global replacement |
Can you guess the output of following command?
:1,$ s/[A-Z]/\l&/g
Congratulation, for successfully completion of this tutorial of regular expressions.
I hope so you have learn lot from this. To master the expression you have to do lot of practice. This tutorial is very important to continue with rest of tutorial and to become power user of Linux. Impress your friends with such expressions. Can you guess what last expression do?
:1,$ s/^ *$//
Note : indicates two black space.
Using & as Special replacement character | awk - Revisited |