How do we validate the header file. The file number should increament by 1 (position 17 to 19) if not abend the process.
first week
ABC0001 20100101123
second week
ABC0001 20100108124
Third week
ABC0001 20100115125
How do we validate the header file. The file number should increament by 1 (position 17 to 19) if not abend the process.
first week
ABC0001 20100101123
second week
ABC0001 20100108124
Third week
ABC0001 20100115125
Hello,
You can extract file number (position 17-19) using cut command below
I am not sure how your file names would be. For eg if you want to check this for list of files in a directory etc.
-Nithin.
I think i didnt give clear picture on wht i needed. My req is like
Assume that source file is available on every week say test_file.dat
#!/bin/sh
CURWEEK=`echo "ABC0001 20100115125" | cut -c18-19`
LASTWEEK=`echo "ABC0001 20100108124" | cut -c18-19`
if [ $CURWEEK -gt $LASTWEEK ];then
#Run your program
fi
diff of CURWEEK & LASTWEEK should be 1
Hope this works
#!/bin/sh
CURWEEK=`echo "ABC0001 20100115124" | cut -c18-19`
LASTWEEK=`echo "ABC0001 20100108125" | cut -c18-19`
if [ `echo "$CURWEEK - $LASTWEEK" | bc` -eq 1 ];then
# Your program
fi
-Nithin
As OP said in his post, the file will be created in an incremental basis and we can not hard code the file-name for comparing with the last file.
the number of the last file must be picked from some temp file each time I think so.
Ex, ( supposing header is the first line ) :
awk 'FNR==1{a[c++]=substr($2,10)+0;b[d++]=FILENAME}
END{
av=a[0]
for (i=1;i<c;i++){
if ( a-av != 1 ) {
print b,": File Out of range !!"
av++
}
else {
av=a
}
}
}' first second third