Fixed Length records- Korne Shell Program.

Hi,

I need some help regarding in writing a Korne shell script, in determining the fixed length records in a data file. We have already utility in place, which does this work. The Code for this is as below. In the below $1 is the parameter passed to the script, which is the data file name.

This script is working for the files which is having characters less than or equal to 10239.

But this script fails for the lengthy data files, where the characters in the file exceeds 10239.

I have got 3 files, which have characters exceeding 13,000 and less than 16,000.

Can anyone let me know, as how to overcome this problem.

======================================================
CHKLEN=`awk 'NR==1 {print length($0)}' $1`
if [ "$CHKLEN" != "" ]
then
awk "length != $CHKLEN { exit 1 }" $1
if [ $? -ne 0 ]
then
return 1
fi

# Add one for CRLF
let CHKLEN=CHKLEN+1
echo $CHKLEN
else
echo 0
fi
return 0

Thanks and Regards,

rajesh

HI,
AWK has a limitation of the length of records.
That is if a single line exceeds certain length, (I think its 1400 if i am not wrong) then it will throw an error.
Check the version of AWK and if possible get a newer version of it.
Better try using perl which is best suited for this.

Thanks
Raghuram

All versions of awk can handle files of any size (subject to memory limitations if you are storing large portions of the file in memory).

With some versions of awk, you could have a problem with long lines. Is that the problem? If so, use GNU awk (gawk).

You don't need to call awk twice:

awk '
   NR == 1 { len = length }
   len && len != length { error = 1; exit }
   END {
             if ( error == 0 ) print len
             else exit 1
          }
'

Hi Johnson,

Can you please post the same equivalent code using gnu gawk?

awaiting your reply.

thanks,

rajesh

gawk '
   NR == 1 { len = length }
   len && len != length { error = 1; exit }
   END {
             if ( error == 0 ) print len
             else exit 1
          }
'