Checking missing data's sequence (shell script | UNIX command)

Dear All members,

i have some trouble here, i want to ask your help. The case is:

I have some data, it's like:
-ABCD1234
-ABCD1235
-ABCD1237
-BCDE1111
-BCDE1112
-BCDE1114

there is some missing data's sequence (the format is: ABCD = name 1234 = sequence).

I want to print the missing sequence (ABCD1236 and BCDE1113) and direct into one file.
Ex:
~more missing-sequence.txt
ABCD1236
BCDE1113

the data above is missing in my directory. Can someone help me to give me an example of shell script to check the missing file?

#!/bin/bash

find . -type f | sed 's/\.\///g' | sort > file_list.dat

awk ' { print substr($1,1,4) } ' file_list.dat | uniq | while read name
do
        str_seq=$( sort file_list.dat | grep $name | head -1 | cut -c 5-8 )
        end_seq=$( sort file_list.dat | grep $name | tail -1 | cut -c 5-8 )

        if echo $str_seq | egrep -q '^[0-9]'
        then
                for sq in $( seq $str_seq $end_seq )
                do
                        if [ ! -f "${name}${sq}" ]
                        then
                                echo "${name}${sq} missing."
                        fi
                done
        fi
done
1 Like
$ nawk 'NR==1{name=substr($0,1,4);seq=substr($0,5,4);next}{name1=substr($0,1,4);seq1=substr($0,5,4); if(name == name1){for(i=seq+1;i<seq1;i++){print name""i}}name=name1;seq=seq1;}' input.txt
ABCD1236
BCDE1113
1 Like