The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script needed to select and delete lower case and mixed case records abhilash mn Shell Programming and Scripting 1 03-17-2008 08:00 AM
Sed - Lower case single characters zlindner UNIX for Dummies Questions & Answers 6 12-09-2007 11:07 AM
Accepting Upper and Lower case lweegp Shell Programming and Scripting 8 12-08-2007 06:57 PM
lower case to upper case string conversion in shell script dchalavadi UNIX for Dummies Questions & Answers 3 05-29-2002 12:07 AM
Upper And Lower Case pciatto Shell Programming and Scripting 1 04-29-2002 12:17 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-08-2008
buechler66 buechler66 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 14
bourne shell - lower case a string

Hi. I came across a script that grabs the 3-char month with this command:

MON=`date "+%b"`


The problem is that we need the return value to be in lower case and this is returning a intial capital letter on the string. So then the script does a bunch of IF statements to force the string to lower case. Like this:


# RECODE THE 3-CHAR MONTH FROM INITIAL CAPS TO LOWER CASE TO MATCH TTMS
# DIRECTORY NAMES ON THE SERVER
if [ $MON = Jan ]
then
month=jan
fi;
if [ $MON = Feb ]
then
month=feb
fi;
...more

Is there a better way to force the string to be lowercase in the bourne shell? Thanks in advance!
  #2 (permalink)  
Old 05-08-2008
fabtagon fabtagon is offline
Registered User
  
 

Join Date: Apr 2008
Location: European Union/Germany
Posts: 189
use command line tool "tr"
  #3 (permalink)  
Old 05-08-2008
buechler66 buechler66 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 14
Thanks. This works fine as long as my string I want to lower case is in a file, but what I really want is to pass the string from the command I'm already using:

MON=`date "+%b"`

Can this be done using the tr command?
  #4 (permalink)  
Old 05-08-2008
fabtagon fabtagon is offline
Registered User
  
 

Join Date: Apr 2008
Location: European Union/Germany
Posts: 189
In Unix, everything is a file ;-)

MON=`date "+%b" | tr ...`
  #5 (permalink)  
Old 05-08-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Without depending on external tools...

Code:
MON=$(date +%b)
case $MON in
    [jJ][aA][nN]) MON="jan" ;;
    [fF][eE][bB]) MON="feb" ;;
.
.
.
    [dD][eE][cC]) MON="dec";;
    *)  echo "Dont know of a MONTH like $MON" ;;
esac
  #6 (permalink)  
Old 05-08-2008
buechler66 buechler66 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 14
Quote:
Originally Posted by fabtagon View Post
In Unix, everything is a file ;-)

MON=`date "+%b" | tr ...`
Perfect! I appreciate all the help.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0