![]() |
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 |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Test variable | javeed7 | Shell Programming and Scripting | 2 | 04-19-2008 07:59 PM |
| to check variable if its non numeric | sachin.gangadha | Shell Programming and Scripting | 3 | 12-06-2007 05:33 PM |
| Perl code to differentiate numeric and non-numeric input | Raynon | Shell Programming and Scripting | 11 | 08-04-2007 10:32 AM |
| How to test if a variable is in the right format | dbrundrett | Shell Programming and Scripting | 2 | 07-05-2004 07:05 AM |
| how to set a variable to accept alpha-numeric characters? | bcaunt | Shell Programming and Scripting | 3 | 06-04-2002 03:42 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
||||
|
I'm trying to test and see whether a variable that is being extracted from a line in a file is numeric or not. I have tried everything that I can think of and I cannot figure out how to get it to work. I am trying to test and see if the string extracted contains 5 numeric digits. This is what I have so far:
case $zipcode in +([0-9])|+([0-9])|+([0-9])|+([0-9])|+([0-9])) if [[ $zipcode -lt 1 ]] && [[ $zipcode -gt 99999 ]] || [[ $zipcount -ne 6 ]] then echo ${myline} echo "ZIPCODE WARNING! -> ${zipcode}" fi ;; *) echo ${myline} echo "ZIPCODE WARNING! -> ${zipcode}" ;; esac |
|
||||
|
Code:
case $zipcode in [0-9][0-9][0-9][0-9][0-9]) ;;
*) echo "$myline"; echo "zipcode warning: $zipcode" >&2;;
esac
Last edited by era; 04-09-2008 at 03:11 PM.. Reason: make it more similar to original |
|
||||
|
Sorry it was a little tedious, but I just tried it your way and it still doesnt work...it prints out zipcode warnings for every line in the file. even the ones that are legit...I'm not sure what we are doing wrong, but is there another way to do it?
|
|
||||
|
There are ways of course, but it would be better IMHO to understand what's wrong here. Does it pass strict numerical test? Does it pass five-character test?
Code:
case $zipcode in *[!0-9]*) echo did not pass all-number test >&2;; esac case $zipcode in ?????) echo did not pass five-character test >&2;; esac |
|
||||
|
I was able to get it to work...sorry it had one leading whitespace that was keeping it from recognizing that the variable was numeric and not a string. Thanks for all your help I really appreciate it.
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|