republican-creole
Search:  

 
 
   All ForumsHot TopicsGallery






how-to block ads


 
Forums » Tech and Talk » OS and Software » All Things Unix » Make variables uppercase in bash.
Search Topic:
Uniqs:
417
Share Topic:
RSS topic:
toggle:
flat / full
normal / watch
Posting:
Post a:
Post a:
Sendmail Config... »
« Grub Question.  
AuthorAll Replies


Maxo
Your tax dollars at work.
Premium,VIP
join:2002-11-04
Tallahassee, FL
clubs:
·Embarq

Make variables uppercase in bash.

I am trying to take part of a string and make it uppercase. For example:
export var='abcdefg'
echo ${var:2:1}

With the exception that I need this to return 'C', not 'c'. The only thing I have been able to find are commands that take a whole file as a parameter and makes it all uppercase. Can anyone help me do this please?


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME

I suppose you can't use tr?

echo ${var:2:1} | tr 'a-z' 'A-Z'

would work, but I take it you want to avoid using tr?
--
He who is not contented with what he has, would not be contented with what he would like to have. -Socrates


Maxo
Your tax dollars at work.
Premium,VIP
join:2002-11-04
Tallahassee, FL
clubs:
All the examples of tr that I saw had to take files. I didn't think about using pipes. I think that should work. I'll try it and let you know.


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
oh ok! cool, should do the trick.


Maxo
Your tax dollars at work.
Premium,VIP
join:2002-11-04
Tallahassee, FL
clubs:
·Embarq

I think I may need to be a little more specific. We are writing a bash script that reads some stuff and builds a control file for Oracle's sqlldr, and then we execute sqlldr with the build control file. Our code looks much like this:

The myAmicFiles just looks like this:
amici.990120
amici.990220
amico.990520
amico.990620

I need the i or o to be uppercase.

--
"Padre, nobody said war was fun now bowl!" - Sherman T Potter

»www.cafepress.com/maxolasersquad

»maxolasersquad.com/

»maxolasersquad.com/network/ My DSL Network Guide

»myspace.com/mlsquad


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
Looks like a good place for a perl script.


Maxo
Your tax dollars at work.
Premium,VIP
join:2002-11-04
Tallahassee, FL
clubs:
·Embarq

said by deblin See Profile :

Looks like a good place for a perl script.
If you knew what Perl and I had been through the last two and a half weeks you wouldn't joke like that.


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME

said by Maxo See Profile :

said by deblin See Profile :

Looks like a good place for a perl script.
If you knew what Perl and I had been through the last two and a half weeks you wouldn't joke like that.
heh! ok, well let me take a look.
--
He who is not contented with what he has, would not be contented with what he would like to have. -Socrates


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME

reply to Maxo
So in this line:

quote:
echo " column3 CONSTANT '" ${LINE:4:1} | tr 'a-z' 'A-Z' "'," >> file_loader.ctl

You want just the capital letter?

E.g. for LINE = amico.990120 you want just the O?

Or do you want amicO.990120 ?
--
He who is not contented with what he has, would not be contented with what he would like to have. -Socrates


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME

reply to Maxo
Probably the easiest thing to do would be to set a variable for the letter first, then just use that variable.

e.g instead of:

bash code:
echo " column3 CONSTANT '" ${LINE:4:1} | tr 'a-z' 'A-Z' "'," >> file_loader.ctl

try:

bash code:
the_char=`echo ${LINE:4:1} | tr a-z A-Z`
echo " column3 CONSTANT '$the_char'," >> file_loader.tcl

Again, assuming you just want the O there and not the full name. If you want the full name, it'd be slightly more involved but not terribly so.

--
He who is not contented with what he has, would not be contented with what he would like to have. -Socrates


Sir Meowmix III

@windstream.net
reply to Maxo
What about using sed?

s/i/I/g s/o/O/g


deblin
Dark Side of the Moon
Premium,MVM
join:2001-09-01
Middletown, DE
·Verizon FIOS
·Comcast Workplace
·DSL EXTREME

said by Sir Meowmix III :

What about using sed?

s/i/I/g s/o/O/g
Good call, that'd work, if he anchor'd it to the ".", e.g.:

bash code:
... | sed 's/o\./O./g' | sed 's/i\./I\./g'

--
He who is not contented with what he has, would not be contented with what he would like to have. -Socrates


Sir Meowmix III

@windstream.net
reply to Maxo
Agree, good call, at that point the regex would be positional on the file extension.


Maxo
Your tax dollars at work.
Premium,VIP
join:2002-11-04
Tallahassee, FL
clubs:
reply to deblin
the_char=`echo ${LINE:4:1} | tr a-z A-Z`
The above line just returns the given string literal, not the results of the echo.


Maxo
Your tax dollars at work.
Premium,VIP
join:2002-11-04
Tallahassee, FL
clubs:
·Embarq

reply to Sir Meowmix III
I've never used sed before and have only recently began reading up on regular expressions.
I read through the man pages and looked at the code you gave. It appears to work with the following code:

The only thing that is missing is how to take the result of this output and store it in a variable.

--
"Padre, nobody said war was fun now bowl!" - Sherman T Potter

»www.cafepress.com/maxolasersquad

»maxolasersquad.com/

»maxolasersquad.com/network/ My DSL Network Guide

»myspace.com/mlsquad


Sir Meowmix III

@windstream.net


Maxo
Your tax dollars at work.
Premium,VIP
join:2002-11-04
Tallahassee, FL
clubs:
·Embarq

said by Sir Meowmix III :

[code]
MYVAR=$(echo $LINE | sed 's/o\./O\./g' | sed 's/i\./I\./g')

echo $MYVAR
[/code]
That did it. Thanks a lot. You can probably tell that we just started learning how to write these scripts a few weeks ago.


Sir Meowmix III

@windstream.net
reply to Maxo
Glad to help Maxo. Feel free to ask for help anytime you get stuck.


nixen
Rockin' the Boxen
Premium
join:2002-10-04
Alexandria, VA
·Cox HSI
·Speakeasy


edit:
November 21st, @12:55PM

reply to Maxo
said by Maxo See Profile :

I've never used sed before and have only recently began reading up on regular expressions.
I read through the man pages and looked at the code you gave. It appears to work with the following code:

The only thing that is missing is how to take the result of this output and store it in a variable.


Or even:
--
The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt. -- Bertrand Russell
-
Forums » Tech and Talk » OS and Software » All Things UnixSendmail Config... »
« Grub Question.  


Thursday, 08-Jan 17:35:17 Terms of Use | Privacy Policy | Hosting by www.nac.net - DSL,Hosting & Co-lo | feedback | contact
over 9 years online! © 1999-2009 dslreports.com.
page compression OFF
Most commented news this week
· [162] New Comcast Throttling System 100% Online
· [112] After 10 Years Of Service, Charter Declares Home 'Unserviceable'
· [111] iTunes Dumps The DRM
· [72] AT&T, Verizon Stocks Tumble
· [59] DOCSIS 3.0 Gets Faster
· [55] Cable To Grab 75% Of New Subs In 2009
· [54] Feds Start Wait List For DTV Converter Coupons
· [48] Verizon Again Tweaks DSL Bundles
· [46] Rumor: Google Cooking Up Own Router
· [43] AT&T Looking For Femtocell Testers
Most people now reading
· How to download windows 7 beta [Microsoft help]
· ERX06 latency [TekSavvy]
· Has Bell figured out how to overcome MLPPP? [TekSavvy]
· [Beta] Windows 7 Beta will be available Friday Jan, 9 2009 [Microsoft help]
· [ Professions] Northrend Herbalism and Mining Tracks [World of Warcraft]
· cashing a check for my child [General Questions]
· Is Blue-Ray here to stay? [General Questions]
· [video] Freak accident- revolving doors [56k lookout! (broadband heavy)]
· Ubuntu v's Windows [Security]
· Archivis' Guide to Naxx (10-man) [World of Warcraft]