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

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.

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.

Is this what you're looking for?

echo $test | awk '{
if (/^0/){
  print "YES"}
else {
  print "NO"}
}'

Regards

After reading the question agian an additional answer to find out whenever both patterns are not matched:

echo $test | awk '{
if (!/^0/&&!/^1/){
  print "Both not matches"}
else {
  print "Starting with 0 or with 1"}
}'

Regards

The shell does not use slashes around case patterns. What you are looking for is

case "$test" in
  0*) echo "starting with zero ;;
  1*) echo " with one" ;;
  *) echo "otherwise";;  # note closing double semicolon here too
esac

awk simply falls through even if there is a match, so you can speculate what this does:

echo $test | awk '
/^0/ { print "starting with zero" }
/^1/ { print "with 1" }
/^[01]/ { print "neither" }
{ print "any of the above" }'