Code:
# AWK 1
gawk -F, '/,'${ThisMonthDOW}' '${ThisMonthMON}' [0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] '${ThisMonthYEA}',/ {
if (NF == 10)
{
split($10, B,"--");
if (B[2] >= B[1])
{print B[2]-B[1] "," $3 "," $10}
else if ((B[1] > B[2]) && (B[2] == 0))
{print "0" "," $3 "," $10}
else if ((B[1] > B[2]) && (B[2] > 0))
{print B[2] "," $3 "," $10}
else if (B[2] == B[1])
{print "0" "," $3 "," $10}
else if (B[2] < B[1])
{print B[1]-B[2] "," $3 "," $10}
}
else if (NF == 11)
{
split($10, B,"--");
if (B[2] >= B[1])
{print B[2]-B[1] "," $3 "," $10}
else if ((B[1] > B[2]) && (B[2] == 0))
{print "0" "," $3 "," $10}
else if ((B[1] > B[2]) && (B[2] > 0))
{print B[2] "," $3 "," $10}
else if (B[2] == B[1])
{print "0" "," $3 "," $10}
else if (B[2] < B[1])
{print B[1]-B[2] "," $3 "," $10}
}
}' ${TagFile}.one.${NMON}.mon > total.entries.${NTIME}.mon.dow
## AWK 2
gawk -F, '/,(Mon|Tue|Wed|Thu|Fri|Sat|Sun) '${ThisMonthMON}' '${ThisMonthDAY}' [0-9][0-9]:[0-9][0-9]:[0-9][0-9] '${ThisMonthYEA}',/ {
if (NF == 10)
{
split($10, B,"--");
if (B[2] >= B[1])
{print B[2]-B[1] "," $3 "," $10}
else if ((B[1] > B[2]) && (B[2] == 0))
{print "0" "," $3 "," $10}
else if ((B[1] > B[2]) && (B[2] > 0))
{print B[2] "," $3 "," $10}
else if (B[2] == B[1])
{print "0" "," $3 "," $10}
else if (B[2] < B[1])
{print B[1]-B[2] "," $3 "," $10}
}
else if (NF == 11)
{
split($10, B,"--");
if (B[2] >= B[1])
{print B[2]-B[1] "," $3 "," $10}
else if ((B[1] > B[2]) && (B[2] == 0))
{print "0" "," $3 "," $10}
else if ((B[1] > B[2]) && (B[2] > 0))
{print B[2] "," $3 "," $10}
else if (B[2] == B[1])
{print "0" "," $3 "," $10}
else if (B[2] < B[1])
{print B[1]-B[2] "," $3 "," $10}
}
}' ${TagFile}.one.${NMON}.mon > total.entries.${NTIME}.mon.dom