Two ways to change case lowercase to uppercase using sed

Change lowercase to uppercase or vice versa using sed

The brute force easy way:

sed ‘y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/’`

That works, but it’s a lot of typing.

The smart way:

’s/./\u&/g’

This matches any character and replaces it with the uppercase version of that character, and does it globally. Does it get any simpler than that?

One use of this would be finding the hardware address of an interface and converting it to all uppercase.

$ cat /sys/class/net/eth0/address
00:11:de:ad:be:ef

$ cat /sys/class/net/eth0/address | sed ’s/.\/u&/g’
00:11:DE:AD:BE:EF

Posted by admica   @   22 June 2010

Related Posts

Like this post? Share it!

Digg Twitter StumbleUpon Delicious Technorati Facebook RSS

1 Comments

Comments
Mar 18, 2011
2:28 am

Nice trick.
Thank you very much @admica

Leave a Comment

Name

Email

Website

Previous Post
« Knoppix Cheat Codes during boot
Next Post
Start a second X session using KDE, Gnome, XFCE, or any desktop environment »
Powered by Wordpress   |   Lunated designed by ZenVerse