Hi,
I need to check a flatfile for various parameters like length of the record, format of record, any tab character present in the record etc.,
for checking presence of tab character, i'm trying to use the following code and i'm not sure if the same is right. Pls Help.
nawk '{print length($0)}' $fdate > filelength.txt
totrec=`cat filelength.txt | wc -l`
i=1
while [ $i -le $totrec ]
if [ $i -gt 1 ] && [ $i -lt $totrec ]; then
if [ D -eq `nawk "(NR==${i}){print}" $fdate | cut -b1` ]; then
if [ `nawk "(NR==${i}){print}" filelength.txt` -eq 3168 ]; then
tabrec=`nawk '/[\t]/ {if (NR==\$i) {print $0} }' $fdate`
echo $tabrec
if [ `nawk '/[\t]/ {if (NR==\$i) {print NR} else {print 0} }' $fdate` ]; then
echo "The Detail record $i has a tab character inside it"
nawk "(NR==${i}){print} $fdate" >> ./error/$fdate.err
else
echo "The Detail record $i looks fine"
nawk "(NR==${i}){print} $fdate" >> ./output/$fdate.dat
fi
else
echo "The Detail record $i length is not proper"
nawk "(NR==${i}){print} $fdate" >> ./error/$fdate.err
fi
else
echo "The Detail record $i format is not proper"
nawk "(NR==${i}){print} $fdate" >> ./error/$fdate.err
fi
fi
i=`expr $i + 1`
done
I check for Record to start with 'D' and total record length to be equal to 3168 and if tab is present in the record.
Thanks in Advance.
Regards,
Aravind. C