![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Count number of occurences of a word | shikhakaul | UNIX for Dummies Questions & Answers | 8 | 06-25-2009 11:10 AM |
| PERL: Simple reg expr validate 6 digits number | BufferExploder | Shell Programming and Scripting | 2 | 09-10-2008 11:15 AM |
| Count the number of occurence of perticular word from file | rinku | Shell Programming and Scripting | 40 | 08-10-2007 07:33 PM |
| word count showing wrong number of lines | tselvanin | UNIX for Dummies Questions & Answers | 3 | 01-06-2004 11:33 PM |
| restrain the number of digits of a PID | mlefebvr | UNIX for Advanced & Expert Users | 1 | 05-27-2002 09:33 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
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
|
|
|||||
|
Quote:
Code:
$ WORD=abcd1234
$ [[ $WORD =~ [0-9]{5}$ ]] && echo OK || echo KO
KO
$ WORD=abcd12345
$ [[ $WORD =~ [0-9]{5}$ ]] && echo OK || echo KO
OK
|
![]() |
| Bookmarks |
| Tags |
| perl, perl shift, shift, shift perl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|