Format problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format problem
# 1  
Old 12-01-2009
Bug 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  
Old 12-01-2009
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)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date Format Problem

I have written a code in Linux environment which compares two dates and print "correct" if 1st date is less than 2nd date. But when I'm running the same code in SunOS environment, "date -d is an illegal format" is the error it is throwing. How different should my code be so that it executes well in... (18 Replies)
Discussion started by: Chandan_Bose
18 Replies

2. Shell Programming and Scripting

Problem with numbers in exponential format

Hi I have a shell scribt with some numbers in exponential format, for example, "1.23456789E +01" Now I would like to bring these numbers into a format without the E. Can someone help me Thanks Flo ---------- Post updated at 10:07 AM ---------- Previous update was at 09:14 AM... (1 Reply)
Discussion started by: sbfly
1 Replies

3. Shell Programming and Scripting

Problem with format numbers

Hello Everyone! I hope you can help me!! I have this little problem: I executed oracle query and the output of the result are in a text file called "DATAFILE.txt", and the value of file is: 97.37 Well, the script compare the result in text file with a condition: ... (5 Replies)
Discussion started by: bobbasystem
5 Replies

4. Shell Programming and Scripting

having problem in date format

if ( $opt{ww} ) { my $week = $opt{ww} ? $opt{ww} : $lot_list->{cal}->getWW(); print "\nStarting at $week\n"; while ( $week > 200430 ) { print localtime() . ": Working on $week\n"; my ($start,$end) = $lot_list->getWeekDates($week); print localtime() . ":... (3 Replies)
Discussion started by: vahnski
3 Replies

5. Shell Programming and Scripting

change format problem

Someone can help for the following fromat change can done by script? i.e. insert the perivous colurm's first variable if below line don't have the varaible start from AXXX.... From A123,B123,C123 B123,C123 A234,B234,C234 A345,B345,C345 B345,C34 B345,C345 B345,C345 A456,B456,C456 ... (2 Replies)
Discussion started by: bleach8578
2 Replies

6. Shell Programming and Scripting

mail format problem:

i need to send 2 diff mail in a single script:Below the script #!/bin/ksh echo "enter the number" read num if then mail -s "test" unix@yahoo.com mail -s "test" 9886767000@nma.vodafone.in,9916138003@nma.vodafone.in else echo "test again" fi... (5 Replies)
Discussion started by: ali560045
5 Replies

7. Shell Programming and Scripting

CSV format problem

studentNo=$1 tmp=/tmp/acc2courses$ID.$$ grep -w "$studentNo" CSE1001 >/dev/null 2>&1 && echo CSE1001 >>$tmp grep -w "$studentNo" CSE1002 >/dev/null 2>&1 && echo CSE1002 >>$tmp grep -w "$studentNo" CSE9001 >/dev/null 2>&1 && echo CSE9001 >>$tmp This is my code, The output in tmp file... (10 Replies)
Discussion started by: ccwq
10 Replies

8. Programming

format problem

hey everyone, Im making a program that prints different patterns using * like this: * *** ***** ******* ***** *** * i am letting the user decide what the number of rows can be, i want the shape to appear on the left (60 spaces from the right) if it is even and on... (5 Replies)
Discussion started by: bebop1111116
5 Replies

9. UNIX for Dummies Questions & Answers

serial no. format problem

Hello guyz.. just want to know whether my doubt can be solve or not..maybe it my company using yyyymmddxx for serial no format..and it cause problems.. first, my adjustments for moving n deleting domain name exceeded xxx per day, and it will cause and effect the yyyymmdd digits. can... (6 Replies)
Discussion started by: unknown2205
6 Replies

10. Programming

Format Problem with vim

Hi, there. Everyone had a great Thanksgiving? I have a slice format problem when I am using vim to edit c++ source code. I don't know how to discribe the problem exactly. You see, usually when I use the command "vi hello.cpp" to write a code, it will have the format like this: #include... (4 Replies)
Discussion started by: HOUSCOUS
4 Replies
Login or Register to Ask a Question