![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Trying to implement case | ssunda6 | Shell Programming and Scripting | 2 | 03-21-2008 02:55 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 |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 Tried implementing throuh awk also. Code:
echo $test | awk '
/^0/ { print "starting with zero" }
/^1/ { print "with 1" }
'
Please provide inputs. Regards. |
| Forum Sponsor | ||
|
|
|
|||
|
The shell does not use slashes around case patterns. What you are looking for is
Code:
case "$test" in 0*) echo "starting with zero ;; 1*) echo " with one" ;; *) echo "otherwise";; # note closing double semicolon here too esac Code:
echo $test | awk '
/^0/ { print "starting with zero" }
/^1/ { print "with 1" }
/^[01]/ { print "neither" }
{ print "any of the above" }'
Last edited by era; 03-23-2008 at 02:45 AM. Reason: Actually the double quotes in 'case "$test" in '... are not required, but I left them in anyway |
|||
| Google UNIX.COM |