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

Converting lowercase character to uppercase

Try the following command
:1,$ s/[a-z]/\u &/g

Above command can be explained as follows:

CommandExplanation
1,$ Line Address location is all i.e. find all lines for following pattern
sSubstitute 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.
gGlobal 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.


Prev
Home
Next
Using & as Special replacement character
Up
awk - Revisited