#!/bin/sh

nomatchfile="/usr/ns/cus/apduidnomatch.txt"

cp /usr/ns/log/nsrecdata.log "/www/flatfiles/tdma/nsrecdata.log"

grep -e ' MANT ASCII TS=' "/www/flatfiles/tdma/nsrecdata.log" | grep -v -f $nomatchfile > "/www/flatfiles/tdma/rawdata.log"

awk -F "[ :]+" '{gsub(/^.*SA: |TS=/,"");
        gsub(/,/, "-")
        sourceaddress=$1
        # Grabs the time
        gsub(/^.*MANT ASCII /,"")
        minute = $3
        second = $4
# If time interval is 2 minutes use this if statement
#        if (minute %2 ==0)
#               {offset = int(second*2)*500}
#        else
#               {offset = int(2*(60 + second))*500}
        offset = int(second * 2) * 500
        # Displays each line in CSV format
        print offset "," sourceaddress > "/www/flatfiles/tdma/tdmachecktemp.log"
}' "/www/flatfiles/tdma/rawdata.log"

sort -k1 -n "/www/flatfiles/tdma/tdmachecktemp.log" | uniq > "/www/flatfiles/tdma/tdmacheck.log"
cat "/www/flatfiles/tdma/tdmacheck.log"
