0

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...
3
  • 2
    A regex for version number parsing
    – slhck
    Feb 15, 2012 at 15:34
  • this perl example I need ksh /shellscript example
    – Eytan
    Feb 15, 2012 at 15:49
  • Fair enough, but you didn't say that anywhere, plus, which Linux doesn't have perl?
    – slhck
    Feb 15, 2012 at 15:53

1 Answer 1

1

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .