The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 01-05-2009
SFNYC SFNYC is offline
Registered User
  
 

Join Date: Jun 2008
Location: New York City
Posts: 95

Code:
$ cat ./testgrep.ksh
#!/bin/ksh

WORD=abc12345

echo $WORD|grep -qE "[[:digit:]]{5}$"
if [ $? -eq 0 ]; then
     echo "Do this with $WORD"
else
     echo "Else do this with $WORD"
fi

WORD2=ab123456

echo $WORD2|grep -qE "[[:digit:]]{5}$"
if [ $? -eq 0 ]; then
     echo "Do this with $WORD2"
else
     echo "Else do this with $WORD2"
fi

WORD3=abc1234

echo $WORD3|grep -qE "[[:digit:]]{5}$"
if [ $? -eq 0 ]; then
     echo "Do this with $WORD3"
else
     echo "Else do this with $WORD3"
fi

exit 0

$ ./testgrep.ksh
Do this with abc12345
Do this with ab123456
Else do this with abc1234