Quote:
Originally Posted by Raynon
Hi All,
How do i modify the below script such that if the input is numeric, it will give the numeric digit, else it will ouput "0"
Code:
echo "xxx" | awk '/^[0-9]+$/'
|
Here is the script that will do for you..
#!/bin/ksh
echo "Digits as input"
read number
test=`echo "$number" | egrep "^[0-9]+$"`
if [ "$test" ]
then
echo "Entered number is a digit"
else
echo "0"
fi
Instead of egrep you can use awk,grep or any command for searching patterns.
Thanks
Namish