![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Egrep cheat sheet anywhere? Looking for meaning of egrep -c | leelm | UNIX for Dummies Questions & Answers | 2 | 01-11-2008 12:37 PM |
| yet another awk field syntax question | prkfriryce | Shell Programming and Scripting | 4 | 03-22-2007 10:13 AM |
| question on egrep | rohitv | UNIX for Dummies Questions & Answers | 10 | 05-25-2006 02:29 PM |
| help with egrep syntax | Gerry405 | UNIX for Dummies Questions & Answers | 3 | 08-06-2005 11:01 AM |
| awk syntax question | hcclnoodles | Shell Programming and Scripting | 2 | 10-28-2004 09:45 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
egrep syntax question
I have a (seemingly) simple question for you guys
I need my script to allow users to enter numbers with either 2 decimal points or with no decimal points. here's the code I have right now for testing, but I can't for the life of me figure out whats wrong! (it's been broken up into 2 different grep statements) decimal=10.500 echo $decimal | egrep -q '[0-9+]' && echo success || echo failure echo $decimal | egrep -q '[0-9+]\.[0-9][0-9]' && echo success || echo failure any insight would be greatly appreciated as this has been the cause of much frustration for me! |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
With egrep:
Code:
printf "%s\n" "$decimal"|egrep '^[0-9]+(\.[0-9][0-9])?$' >/dev/null && echo OK||echo KO Code:
printf "%s\n" "$decimal"|egrep -q '^[0-9]+(\.[0-9]{2})?$' && echo OK||echo KO
Code:
[[ "$decimal" =~ ^[0-9]+(\.[0-9]{2})?$ ]]&&echo OK||echo KO
.00 and 00. to be considered OK. |
||||
| Google The UNIX and Linux Forums |