![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | 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. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
can any one know that how can i get perfect format of phone number my function is Code:
phone_number=`echo $name_number | awk '{print $NF}'`
check=`echo $phone_number | egrep -c "[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]"`
i get the format but if i need perfect format like xxx-xxx-xxxx. if i enter not in this format it still accept . Last edited by pludi; 12-01-2009 at 06:24 PM.. Reason: code tags, please... |
|
|||
|
try something like this: Code:
echo "$PHONE" | egrep '^[0-9]{3}-[0-9]{3}-[0-9]{4}$' > /dev/null
if [[ $? -eq 0 ]] ; then
echo "good number"
else
echo "bad number"
fi
(egrep may have the -q option on your system instead of redirecting output to /dev/null) |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| phone format problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| change format problem | bleach8578 | Shell Programming and Scripting | 2 | 04-09-2009 05:34 AM |
| CSV format problem | ccwq | Shell Programming and Scripting | 10 | 08-06-2007 03:16 AM |
| format problem | bebop1111116 | High Level Programming | 5 | 10-10-2006 11:41 AM |
| serial no. format problem | unknown2205 | UNIX for Dummies Questions & Answers | 6 | 12-05-2005 11:45 PM |
| Format Problem with vim | HOUSCOUS | High Level Programming | 4 | 12-04-2003 04:31 PM |