Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

with the following command I can verify/match if param have numbers or "."

  param=2.3.1
  echo $param |  grep [0-9][.] 

but what I need to add in my syntax in order to verify also if I have at least two numbers (number or more on the right side and number or more on the left side)

example of valid numbers

 12.2
 1.2
 4.3.0
 123.4.223
 12.33.22.4.2
 1.0.2.3.4

example of not valid numbers

 .39274
 1233.
 .7.
 .5666666.
 2...
share|improve this question
2  
A regex for version number parsing –  slhck Feb 15 '12 at 15:34
    
this perl example I need ksh /shellscript example –  Eytan Feb 15 '12 at 15:49
    
Fair enough, but you didn't say that anywhere, plus, which Linux doesn't have perl? –  slhck Feb 15 '12 at 15:53
add comment

1 Answer

This works in bash(I don't have ksh):

grep '^\([0-9]\+\.\)\+[0-9]\+$'
share|improve this answer
    
this example not work? echo 2.3.34.32_445454 | grep '^([0-9]\+\.)\+[0-9]\+$' –  Eytan Feb 15 '12 at 16:12
    
@Eytan: echo 2.3.34.32.445454 | grep '^\([0-9]\+\.\)\+[0-9]\+$' works. Why do you use underscore(_)? –  kev Feb 15 '12 at 16:17
    
because the numbers can be with any char as "_" –  Eytan Feb 15 '12 at 22:26
    
@Eytan change [0-9] to [0-9_] –  kev Feb 16 '12 at 0:43
    
this syntax not work on solaris –  Eytan Feb 16 '12 at 11:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.