The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Trying to implement case ssunda6 Shell Programming and Scripting 3 03-23-2008 02:44 AM
Script needed to select and delete lower case and mixed case records abhilash mn Shell Programming and Scripting 1 03-17-2008 04:00 AM
To CASE or not to CASE, this is my question! olimiles Shell Programming and Scripting 1 08-19-2006 01:54 AM
Ignore case sensitive in Case Switch annelisa Shell Programming and Scripting 1 07-13-2006 01:36 AM
lower case to upper case string conversion in shell script dchalavadi UNIX for Dummies Questions & Answers 3 05-28-2002 09:07 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-21-2008
Registered User
 

Join Date: Feb 2008
Posts: 7
Stumble this Post!
Trying to implement case

Hi All,

My requirement is if the record is starting with 0, then do some processing.
if starting with 1, some processing
else (not with 0 or 1 ) then do some other processing.

i tried the following
Code:
case "$test" in
/^0/) echo "starting with zero ;;
/^1/) echo " with one" ;;
*) echo "otherwise"
esac
Though the record is starting with zero, it is printing "otherwise" everytime.

Tried implementing throuh awk also.

Code:
echo $test | awk '
/^0/ { print "starting with zero" }
/^1/ { print "with 1" }
'
But I am unable to figure out how to tell awk to do something whenever both the patterns are not matched.
Please provide inputs.
Regards.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-21-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/florida
Posts: 946
Stumble this Post!
Here is a short example:

Code:
#!/usr/bin/ksh93

test="01234"

print "test=$test"

case ${test} in
0*)  print "started with zero";;
1*)  print "started with one";;
*)   print "otherwise";;
esac

exit 0
Reply With Quote
  #3 (permalink)  
Old 03-21-2008
Registered User
 

Join Date: Feb 2008
Posts: 7
Stumble this Post!
Hi

Thanks a lot. It is working.
Missed a simple logic.

Regards.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0