Checking missing file based on sequence number

February 25, 2012 at 04:46:28
Specs: Solaris
Hi Experts,

Have you tried doing a script for checking if there is a missing file based on the sequence number? Im tried doing it but I cannot achieve the correct output using AWK.

For Example:

Input:

FILE001
FILE002
FILE005
FILE006
FILE008
FILE009
FILE010
FILE014

Output:
FILE003
FILE004
FILE007
FILE011
FILE012
FILE013


Does anybody tried doing this before? Any input is highly appreciated.

Thank you in advance.

Regards,
Amiti


See More: Checking missing file based on sequence number

Report •

#1
February 25, 2012 at 23:55:48

#!/bin/ksh

awk ' BEGIN { lcnt=1 }
{
if(NR == 1)
   fbase=substr($1,1,(length($1) - 3) )

seqno=substr($1,(length($1) - 2) ) + 0
# the for loop prints any gap
for(i=(lcnt+1); i<seqno; i++)
    printf("%s%03d\n", fbase, i)
# save the previous sequence number
lcnt=seqno

} ' input > output


Report •
Related Solutions


Ask Question