script to ensure lines are in sequence

Hello there,
I check files containing more than 2000 lines, I try to make sure that the lines are in sequence...for example the first line begins with Av567, second line contains Av568 and so on up to the last line that may contain Av2500.

I need a script to check that all lines are in sequence and if a line is skipped or not in sequence with the rest of the lines it tells me where is this line.

this will save me a lot of time, I'll be thankful for you if you can help

A sample of some lines of your file would be helpful.

Regards

awk:

>cat file
Av567 linea1
Av568 linea2
Av569 linea3
Av570 linea4
Av571 linea5
>awk '{gsub(/Av/,"",$1)
if ( NR ==1 ) 
   init=$1
else
   if ( $1 != init+NR-1 )
      {
      t=1
      print "Av"$0" : Not in sequence"
      exit
      }
}
END {
if (!t)
   print "Good sequence"
}'  file
Good sequence
>cat file
Av567 linea1
Av568 linea2
Av569 linea3
Av572 linea4
Av573 linea5
>awk '{gsub(/Av/,"",$1)
if ( NR ==1 ) 
   init=$1
else
   if ( $1 != init+NR-1 )
      {
      t=1
      print "Av"$0" : Not in sequence"
      exit
      }
}
END {
if (!t)
   print "Good sequence"
}'  file
Av572 linea4 : Not in sequence

Or in ksh:

i=0
while read w1 r
do
n=${w1#Av}
if (( i == 0 ))
then
init=$n
else
if (( n != ( init + i ) ))
then
echo "Not in sequence: $w1 $r"
break
fi
fi
(( i += 1 ))
done<file[/CODE]

sort -nc file perhaps?

typeset -i line_no kine i ln
IFS="\n"
line_no=`cat Invalid_text.txt| awk '{print $1}'|cut -c2-4| tail -1`
i=567
cat Invalid_text.txt| awk '{print $1}'|cut -c2-4 > seq_tmp
ln=`cat seq_tmp |wc -l`
ctr=1
while [ $ctr -le $ln ]
do
line=`cat seq_tmp | head -$ctr |tail -1`
#[ $i -le $line_no ]

    if [ $line -ne $i ]
    then
            echo "Sequence skipped. $i is not there"
    fi

i=`expr $i + 1`
ctr=`expr $ctr + 1`
done

Another bash or ksh solution :

while read avseq filler
do
   echo $avseq
   seq=${avseq#Av}
   while [ $seq -gt ${next_seq:=$seq} ]
   do
      echo "Missing sequence Av$next_seq"
      (( next_seq += 1 ))
   done


   if [ $seq -lt $next_seq ]
   then
      echo "Retrograde sequence  Av$seq"
   fi

   (( next_seq = seq + 1 ))
done < inputfile

Input file:

Av567 linea1
Av568 linea2
Av569 linea3
Av572 linea4
Av573 linea5
Av570 linea6
Av571 linea7

Ouput:

Av567
Av568
Av569
Av572
Missing sequence Av570
Missing sequence Av571
Av573
Av570
Retrograde sequence  Av570
Av571

Jean-Pierre.