Operating System - HP-UX
1848453 Members
5879 Online
104029 Solutions
New Discussion

Re: conversion from small to CAPS lets.

 
deepak_9
Frequent Advisor

conversion from small to CAPS lets.

Hi Forum,

Wann to know how to covert string of "small letters" into CAPS one.

Please reply asap.

Regards
Never Ever give Up !!!!!
13 REPLIES 13
federico_3
Honored Contributor

Re: conversion from small to CAPS lets.

you can like this:


echo "string"| dd conv=ucase
Darrell Allen
Honored Contributor

Re: conversion from small to CAPS lets.

Hi,

Use tr. From man tr:

Translate all lower case characters in file1 to upper case and write the result to standard output.
tr "[:lower:]" "[:upper:]"
Or: echo string | tr "[:lower:]" "[:upper:]"

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
federico_3
Honored Contributor

Re: conversion from small to CAPS lets.

Another way could be the following:

echo "string"| tr "[:lower:]" "[:upper:]"
Dave Peeke
Occasional Advisor

Re: conversion from small to CAPS lets.

typeset -u string
string="test"
echo $string
TEST
harry d brown jr
Honored Contributor

Re: conversion from small to CAPS lets.

echo this is a test | tr "[a-z]" "[A-Z]"

live free or die
harry
Live Free or Die
deepak_9
Frequent Advisor

Re: conversion from small to CAPS lets.

Hi,

The answers are quite satisfactory but what if I wann to retain the file extensions as it is...I mean for "abc.sql", it should be "ABC.sql" convention.

Thanks
Never Ever give Up !!!!!
Robin Wakefield
Honored Contributor

Re: conversion from small to CAPS lets.

Hi Deepak,

If you only have a "single" dot, then

echo abc.def | awk -F. '{print toupper($1)"."$2}'
ABC.def

should be OK.

Rgds, Robin.
Jeff Machols
Esteemed Contributor

Re: conversion from small to CAPS lets.

you would do something like this

NAME=`echo $STRING | awk -F. '{print $1}'
EXT=`echo $STRING | awk -F. '{print $2}'
Darrell Allen
Honored Contributor

Re: conversion from small to CAPS lets.

If you want to limit your translation to files with only 1 dot in them:

for i in `ls *\.*`
do
cnt=`echo $i | awk -F. '{print NF}'`
if [ ${cnt} -eq 2 ]
then
echo $i | awk -F. '{print toupper($1)"."$2}'
fi
done

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Darrell Allen
Honored Contributor

Re: conversion from small to CAPS lets.

A refinement to my last post:

for i in `ls *\.*`
do
echo $i | awk -F. '{if (NF == 2) print toupper($1)"."$2}'
done

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Craig Rants
Honored Contributor

Re: conversion from small to CAPS lets.

Since I did not see the sed version

sed filename 'y/abc...xyz/ABC...xyz/'

fill in the ... part with then entire alphabet. Of course this is not the pretty way to do things, but it is the sed way.

Enjoy,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
federico_3
Honored Contributor

Re: conversion from small to CAPS lets.

i'd do like the following:

ls -1 abc.sql | awk -F "." '{system("mv" ""$0 "" toupper($1) ".sql" }'
federico_3
Honored Contributor

Re: conversion from small to CAPS lets.

i'd do like the following:

ls -1 abc.sql | awk -F "." '{system("mv" " " $0 " " toupper($1) ".sql" }'