views:

411

answers:

3

How can I change the case of a matching group from lower to uppercase with sed Unix command?

Thanks Martin

+3  A: 

Run it through tr?

Just kidding. You can use the y/// transform to do case changes. It's not terribly convenient, but it's functional. If your transform gets too complex, you may want to consider escalating to perl.

tylerl
+1  A: 

I know this is a sed question just wanted to point out there are several ways to do that function. awk is a tool that was made for text wrangling and in some cases is easier to use. In my opinion this is one of these times:

#!/bin/sh
INFO="This is a test"
ALLCAPS=`echo $INFO | awk '{print toupper($0)}'`
echo $ALLCAPS

Yields: THIS IS A TEST

John Place
+2  A: 

Surround your matching pattern in parentheses ie: \(pattern\) and then use \U\1 as the replacement text. \1 is the matching pattern and \U forces uppercase.

echo abcdef | sed -e 's/\(abc\)/\U\1/'
Howard Hong