Hi,
I want to find out whether a string contains non numbers and + and -
example :
Str="0005000A" - It contains A
Str="0005000+" - No problem
What I have done is ,
echo $Str | grep [a-z,A-Z]
I will have to list out all non numeric characters here..
Is there any easy way of doing it...
Shihab
reborg
2
echo $Str | grep '[^0-9+\-]'
Ygor
3
Try...
Chk=$(echo $Str | tr -d '[0-9+\-]')
if [[ -n $Chk ]]
then
echo It contains $Chk
else
echo No Problem
fi
I think that the OP wants to get all strings that contain non numeric chars. So you would be leaving only the [0-9] in the grep or the tr.
i.e.
echo $Str | tr -d '[0-9]'
or
echo $Str | grep '[^0-9]'
reborg
5
No that's not what OP asked for, it's exactly what Ygor posted, or if you chec the exit value what I posted.
just number with + or - are ok, anthing esle is not.
Oops.. sorry reborg, missed the second example there...
reborg
7
Sorry if my post seemed abrupt, it wasn't intended that way, I was really short on time and my response came out a bit clipped.