I want the grep(posix) match floating point in a FILE which contains only single line where floating point separate by blank space between them.
the FILE:
12 3.14 1.1.2.4
my regex is:
grep -E "^[[:digit:][:blank:]\.]*\.?[[:digit:]]+$" FILE
regex was successfully matching "| 12 | 3.14 | 1.1.2.4 |" in single line, but we expecting normal floating point to be match like "| 12 | 3.14 |" but not "| 1.1.2.4 |" because it's contain multiple dot which invalid floating point. Can anyone help me use right regex pattern with grep(posix) to match floating point in one line separate by blank space in single line? because i use grep as function to evaluate floating point.
You may try this grep
:
grep -oE '(^|[[:blank:]])([[:digit:]]+(\.[[:digit:]]+)?|\.[[:digit:]]+)([[:blank:]]|$)' file
12
3.14