the following code works perfectly for me:
# 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
However, as you can see, it is inefficient as im running awk on a log file 2 different times when I should be able to run it once.
my question is, how can i combine this into one? so that it takes the different log files as arguments. and then searches for the distinct patterns in each of the log files and then outputs the results to the different text files ending in ".dow" and ".dom".