Character first registration

friends
I have the following code that works perfect

while read linea
     do


       largo=${#linea}
       echo "largo es///////////: $largo "


      if [ $largo -ne 171 ]
       then
         echo "Longitud De Registro Invalida"
         echo " $linea > ERROR DE LONGITUD"  >>  $PATH_DAT/$ArchSalida
       fi
     done <  ${PATH_DAT}/$ArchPro #while read linea

before this condition

if [ $largo -ne 171 ]
       then
         echo "Longitud De Registro Invalida"
         echo " $linea > ERROR DE LONGITUD"  >>  $PATH_DAT/$ArchSalida
       fi

I need to ask for the first 2 characters in the record

An old school way:

expr "${linea}" : '\(..\)'

What shell are you using?
What operating system are you using?

With a 1993 or later ksh (called ksh93 on some systems) or with a recent bash , you can use a substring parameter expansion:

${linea:0:2}

to get the 1st two characters. (The general format is:

${variable:offset:length}

where the 1st character of the string has offset zero (not one).)