how to find lenght of fixed width file record?

actually i am trying to find the lenght of fixed width file record reading from teradata db but its not working can u guys help me out?

code which i wrote---

colmn_lngth=`cat $RPT_FILE | awk -F~ '{print $1}'`
 
 rm $RPT_FILE
 
 
 while read line
 do
 
  result=`echo $line | wc -m`
  result=`expr $result - 1`
    
   if [ $result -le $colmn_lngth ]; then
        echo $line >> $Src_File.temp
   else
       echo $line >> $Src_File.bad
   fi
 done < $Src_File 

but in file if record is having spaces in between then its not counting tht spaces so it is creating wrong validation.
and writing tht record in to file also its not going properly ....plzs guys can any help out with this issue.plzs

is this fix width right..?

try

awk '{ print (length($0))}' file

if it is same for all the rows..
use..

awk 'END{ print (length($0))}' file

'fixed width records' does not necessarily mean carriage control ("\n") at the end of a line. It just means the data are laid out in a fixed pattern, probably with no character to mark then end of the line. If it is a fixed record length file with carriage control, then just read the very first line.

awk '{print length($0); exit}' infile

Without carriage control you will have a much harder time finding the record length, generally you need to get that information from a source external to the file: file metadata, specifications, someone who knows.

echo 123123123 | read var
echo ${#var}
9

actually wht ever command which i gave is working in intractive mode but when i run d program it removing spaces in record and returning d record count d same while writing in to file.
thaxz fr reply in advance.

---------- Post updated at 10:51 AM ---------- Previous update was at 08:55 AM ----------

can any give me code fr d below
Actually i am reading a record from teradata db table i.e, fixed width with spaces in between, now i want to find good record from tht file according to record length if length is more than the fixed width file length then it will remove tht error record to new file from base file. we will give file as parameter. Plzs help out in this