lorcan,
In this script--
#!/usr/bin/ksh
inpFile=$1
outFile="$HOME/Output.txt"
errFile="$HOME/Error.txt"
dupFile="$HOME/Duplicate.txt"
tmpFile1="/tmp/sample1.txt"
tmpFile2="/tmp/sample2.txt"
sortFile="/tmp/sortfile.txt"
TOTAL_FILEDS=9
COUNT=1
PRINT_FLAG=0
LINE_NO=1
check_lines=0
rm -f $outFile $errFile
sort $inpFile | uniq -d > $dupFile
#sort $inpFile | uniq -d | sed "s/$/& : Duplicate/g" >> $errFile
for line in $(cat $inpFile)
do
count_fields=$(echo $line | sed "s/00,*//g;s/,$//g" | wc -c)
echo "count_fields is: $count_fields"
cnt_flds1=$(echo $line | cut -d',' -f1-9 | sed "s/00,*//g;s/,$//g" | wc -c )
echo "cnt_flds1 is : $cnt_flds1"
cnt_flds2=$(echo $line | cut -d',' -f10-18 | sed "s/00,*//g;s/,$//g" | wc -c )
echo "cnt_flds2 is : $cnt_flds2"
cnt_flds3=$(echo $line | cut -d',' -f19-27 | sed "s/00,*//g;s/,$//g" | wc -c )
echo "cnt_flds3 is : $cnt_flds3"
if [[ $count_fields -eq 45 && $cnt_flds1 -eq 15 && $cnt_flds2 -eq 15 && $cnt_flds3 -eq 15 ]]
then
PRINT_FLAG=0
echo $line | cut -d',' -f1-9 > $sortFile
echo $line | cut -d',' -f10-18 >> $sortFile
echo $line | cut -d',' -f19-27 >> $sortFile
while [[ $COUNT -le $TOTAL_FILEDS ]]
do
cut -d',' -f$COUNT $sortFile | grep -v 00 > $tmpFile1
cut -d',' -f$COUNT $sortFile | grep -v 00 | sort > $tmpFile2
diff $tmpFile1 $tmpFile2 > /dev/null
if [[ $? -eq 1 || ! -s $tmpFile1 ]]
then
PRINT_FLAG=1
break
fi
COUNT=$((COUNT+1))
done
echo "Value of print flag is : $PRINT_FLAG"
if [[ $PRINT_FLAG -eq 0 ]]
then
echo "$line : SUCCESS" >> $outFile
else
echo "$line : ERROR in $COUNT" >> $errFile
fi
else
echo "$line : Out of Scope" >> $errFile
fi
COUNT=1
check_lines=$((check_lines+count_fields))
if [[ $LINE_NO -eq 6 ]]
then
LINE_NO=0
if [[ $check_lines -eq 270 ]]
then
echo " **** Success ***** "
else
echo "----- Error,Check the above -----"
fi
check_lines=0
fi
LINE_NO=$((LINE_NO+1))
done
rm -f $tmpFile1 $tmpFile2 $sortFile
exit 0
When i am running the script,the value of PRINT_FLAG is getting 1 that means the data is not in sort order,trying to debug but i am not able.Please help me out in this.
The input File is --
03,00,00,00,41,56,00,73,84,04,17,22,32,00,00,00,76,00,00,19,29,00,49,00,64,00,86
77,00,00,30,40,57,00,75,00,00,00,25,37,00,58,68,00,81,00,16,00,00,46,00,69,77,89,12
03,00,24,34,00,50,00,79,00,00,16,00,00,46,54,62,00,90,07,00,28,38,49,00,68,00,00,54
00,12,00,35,00,55,00,70,82,00,13,23,00,48,00,60,00,87,08,00,00,00,00,58,66,71,88
07,00,23,00,46,00,62,00,83,00,10,00,34,47,00,66,72,00,09,13,29,00,00,52,00,00,90,09
00,00,00,31,44,50,67,73,00,04,19,22,32,00,00,00,00,86,06,00,00,00,48,59,69,76,00
11,00,20,30,00,00,65,79,00,03,00,21,00,46,51,00,00,85,07,17,00,33,47,00,00,00,87,87,00
00,14,00,31,00,57,63,70,00,04,00,24,00,45,59,00,00,90,00,15,25,35,00,00,66,71,00
00,12,23,00,48,50,00,00,84,08,00,00,36,00,00,60,73,88,00,16,00,37,49,52,00,75,00
05,00,22,00,00,55,64,00,80,06,11,26,00,41,00,00,72,00,00,13,00,32,00,00,67,78,83
66,11,00,34,41,00,63,00,00,07,00,29,00,00,57,00,72,81,00,15,00,00,49,58,68,76,00,87
00,11,21,00,00,55,00,73,83,07,00,22,39,43,00,66,00,00,00,15,00,00,44,58,67,00,87
00,12,25,00,00,50,61,00,85,01,15,00,31,00,00,00,79,88,00,00,29,00,41,52,62,00,90
00,00,21,34,00,51,61,00,83,08,18,00,00,43,00,00,78,88,00,00,26,36,00,59,62,79,00