Case conversion within a command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Case conversion within a command
# 1  
Old 07-09-2013
Case conversion within a command

Hi All,

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

Code:
DATABASE=ORCL

something like the below which is absolutly wrong

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

The o/p should be as below:

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

Please advise. Will be of great help.

Thanks
JJOY
# 2  
Old 07-09-2013
Try:
Code:
find /ora/admin/11.1.0/diag/rdbms/`echo "$DATABASE" | tr "[A-Z]" "[a-z]"`/`echo "$DATABASE" | tr "[a-z]" "[A-Z]"`

# 3  
Old 07-09-2013
are you using bash?

if yes below can be used
Code:
 
${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
This User Gave Thanks to vidyadhar85 For This Post:
# 4  
Old 07-09-2013
Another option:

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

# 5  
Old 07-09-2013
Thanks Bartus11, this worked Smilie
Thanks others, who replied to this.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Conversion program/command via CLI

I already know about the docx2txt program, and it's extremely helpful. ssconvert is also really helpful, but unlike docx2txt, it works both ways. How does one convert a .txt file to .docx via CLI, or is it even possible?? This: docx2txt example.docx results in making a .txt file out of... (2 Replies)
Discussion started by: Huitzilopochtli
2 Replies

2. UNIX for Dummies Questions & Answers

EBCDIC TO ASCII Conversion through UNIX Command

Hi All , I have a mainframe file which contains the data in EBCDIC unreadable format.I have downloaded this raw unreadable file from mainframe system to windows in text format then I pushed to Unix system.Now I want to convert this file to ASCII readable format file in unix.Can anyone advise me... (2 Replies)
Discussion started by: STCET22
2 Replies

3. UNIX for Dummies Questions & Answers

Selective case conversion of a file

Hi all, I have a requirement to convert a file from one format to another. Parent file: to i.e., 1.) all the lines which begin with "Sample:", should be converted in such a way that entire text after ":" gets converted into all-lower case. 2.) all the lines which begin with... (7 Replies)
Discussion started by: dipanchandra
7 Replies

4. Shell Programming and Scripting

Characterset conversion problem using iconv command

Hi Friends, I am not able to conver character set from UTF-8 to IBM-284 throwing an error "cannot open convertor" . Could you please help me how to get out of this error. Below command is working fine iconv -f ISO8859-15 -t UTF-8 fromfile.txt > tofile.txt But the below command is... (2 Replies)
Discussion started by: sivakumarl
2 Replies

5. Shell Programming and Scripting

Conversion from Upper Case to Lower Case Condition based

Hello Unix Gurus : It would be really appreciative if can find a solution for this . I have records in a file . I need to Capitalize the records based on condition . For Example i tried the following Command COMMAND --> fgrep "2000YUYU" /export/home/oracle/TST/data.dat | tr '' ''... (12 Replies)
Discussion started by: tsbiju
12 Replies

6. Shell Programming and Scripting

Date command output conversion

hi all, i need to measure time difference between the time a process started, to the time it ended. i am assuming the following are the steps: 1. output 'date' command at start time 2. output 'date' command at end time 3. subtract the two question is, how do i subtract the two time... (4 Replies)
Discussion started by: rathajs
4 Replies

7. Solaris

Bad command error for date conversion

Hi, Iam trying to convert date and time to milliseconds which iam using in a script on Sun Solaris. I have searched the posts on the forum but i could not get any solution. The format iam using in script is: date -u "Thu Dec 24 00:01:00 EST 2009" But i get a bad command error. ... (6 Replies)
Discussion started by: jyothi_wipro
6 Replies

8. Shell Programming and Scripting

Command for unix to dos conversion

Dear All Could you please advice how do we convert a unix file to dos I know one command,ux2dos, which somehow does not work to give desired output Inputs on this is appreciated Thanks, Suresh (3 Replies)
Discussion started by: sureshg_sampat
3 Replies

9. Shell Programming and Scripting

Need help in Case Command

Hi All I am trying to replace some character using Sed , but i also need to use case commands like this : x=`who am i` opt=`echo ${x} | cut -f1 -d' '` case $opt in unix) 'UNX' My script asks the user to enter the source server and it gets the results it has to reaplace the above... (5 Replies)
Discussion started by: raghav1982
5 Replies

10. UNIX for Dummies Questions & Answers

lower case to upper case string conversion in shell script

How can convert a Lower case variable value to an upper case in the kron shell script. (3 Replies)
Discussion started by: dchalavadi
3 Replies
Login or Register to Ask a Question