Script Error token '08'

Hi anybody
kindly help me to overcome this error,
in my following UNIX script the value of substr is the Hour position in processing records, and I want to seperate only 00 to 09 records to a seperate file, when I run this script when it reaches to 08 hour containg record it gives me 08: value too great for base (error token is '08') msg and loop goes out.

Highly appreciate if you solve this problem
tks
# ***************************************************
cat EventLogFile.txt |while read line
do
HOUR=`echo $line | awk '{printf("%s\n",substr($line,21,2))}'
hr=$HOUR

if [[ $hr -ge 0 && $hr -le 9 ]]
then
echo $line >> Event00_09on$(date "+%d")
echo "Record processing "
else
echo "Record negletting "
echo $line
fi
done
# ************************************************

I faced the same issue yesterday. Perderabo pointed me to thread

This issue is caused by numbers starting with 0 being treated as octal numbers. 08 and 09 are invalid octal numbers, thus the message comes up. You can change the base to 10 by using 10# in front of the number.

Here's an example

let "num=10#08"

echo $num
8

:smiley: It worked Thank you so much ...

Kindly tell me how to convert Charactor string (like 7865) to numaric value & numeric value to charactor string.

You can also do all the work using awk only. In that case you will not have problem with pseudo octal numbers.

awk -v File=Event00_09on$(date "+%d") '
   {
      hr = substr($0,21,2);
      if (hr >= 0 && hr <= 9) {
         print "Record processing ";
         print $0 >> File;
      } else {
         print "Record negletting ";
         print $0;
      }
   }
   ' EventLogFile.txt

Jean-Pierre.