Case conversion within a command

Hi All,

I need the variable to be set in both uppercase and lowercase in a single command

DATABASE=ORCL

something like the below which is absolutly wrong

find /ora/admin/11.1.0/diag/rdbms/{print tolower($0)}${DATABASE}/{print toupper($0)}${DATABASE} 

The o/p should be as below:

find /ora/admin/11.1.0/diag/rdbms/orcl/ORCL 

Please advise. Will be of great help.

Thanks
JJOY

Try:

find /ora/admin/11.1.0/diag/rdbms/`echo "$DATABASE" | tr "[A-Z]" "[a-z]"`/`echo "$DATABASE" | tr "[a-z]" "[A-Z]"`

are you using bash?

if yes below can be used

 
${parameter^}      # Convert the first character in ${parameter} to uppercase
${parameter^^}     # Convert all characters in ${parameter} to uppercase
${parameter,}      # Convert the first character in ${parameter} to lowercase
${parameter,,}     # Convert all characters in ${parameter} to lowercase

if not use tr

1 Like

Another option:

echo "find /ora/admin/11.1.0/diag/rdbms" | awk -F"/" -v db=$DATABASE 'BEGIN{OFS="/";}{$7=tolower(db);$8=toupper(db)}1'

Thanks Bartus11, this worked :b:
Thanks others, who replied to this.:slight_smile: