Hey again,
I have a basic regex that tests if a number is a float.
Thank you.
Hey again,
I have a basic regex that tests if a number is a float.
Thank you.
sed -n '/^-*[0-9]*[.]*[0-9]*$/p' myFile
Thanks for the reply.
Sadly that regex allows for multiple minus signs and multiple decimal points.
For example:
------------------9......................3
Is valid with that regex.
Thanks anyway, though.
It doesn't take much of a change:
$ sed -En '/^-?[0-9]*[.]?[0-9]+$/p' file
-10.4
1.0
(if your sed doesn't support extended regular expressions, grep surely will grep -E '^-?[0-9]*[.]?[0-9]+$' file
)
I prefer to use the shell rather than an external command.
This is a beginning (I'm not at my computer right now so I don't have the full function):
is_fpnum()
{
case $1 in
*[!-0-9]* | *.*.* | -*-* ) ## add invalid patterns as needed
return 1;;
esac
}
Disregard the last post I made, I had a stupid error in it. All working now.
Thank you, all.