The UNIX and Linux Forums  


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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-01-2009
Registered User
 

Join Date: Jun 2009
Posts: 3
Smile Format problem

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...
  #2 (permalink)  
Old 12-01-2009
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,006
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
Reply

Bookmarks

Tags
phone format problem

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0