Don, my challenge now is putting date on total and averate. Putting a timestamp.. Trying every combination and googling..
------ Post updated at 11:34 AM ------
I modified it to
printf("\n%s,%s,%d,total", last, last, total)
printf("\n%s,%s,%.1f,average\n", last, last, total / count)
For parsing, but im hoping to have value like this
"date"baabbb4,baabbb4,101.95,total
"date"baabbb4,baabbb4,101.95,average
------ Post updated at 11:45 AM ------
I tried to add the line below
awk '
function print_total() {
printf("\n%s,%s,%d,total", last, last, total)
printf("\n%s,%s,%.1f,average\n", last, last, total / count)
printf("%s", cmd)
}
#{ cmd = system("date") }
{ cmd = system("date ") }
But when i put it in printf,,its throwing a lot of error..
------ Post updated at 12:05 PM ------
awk '
function print_total() {
printf("\n%s,%s,%d,total", last, last, total)
printf("\n%s,%s,%.1f,average\n", last, last, total / count)
# printf("%s", cmd)
}
#{ cmd = system("date") }
last != substr($1, 1, 7) {
if(NR > 1) {
print_total()
printf("\n\n")
}
last = substr($1, 1, 7)
count = total = 0
}
{
print
count++
total += $2
}
{ cmd = system("date") }
END { print_total()
}'
output:
remotese01 120.653 Mbps
Fri Aug 17 17:02:26 UTC 2018
remotese02 91.7216 Mbps
Fri Aug 17 17:02:26 UTC 2018
remotese,remotese,212,total
remotese,remotese,106.2,average
thats what i got..
im hoping of the output below
Fri Aug 17 17:02:26 UTC 2018, remotese,remotese,210,total
Fri Aug 17 17:02:26 UTC 2018, remotese,remotese,105.1,average
------ Post updated at 01:28 PM ------
I found a way.. but ugly..
revise code:
awk '
function print_total() {
printf("\n,%s,%s,%d,total", last, last, total)
printf("\n,%s,%s,%.1f,average\n", last, last, total / count)
# printf("%s", cmd)
}
#{ cmd = system("date") }
last != substr($1, 1, 7) {
if(NR > 1) {
print_total()
printf("\n\n")
}
last = substr($1, 1, 7)
count = total = 0
}
{
print
count++
total += $2
}
END { print_total()
}' rawdata.log |sed -e "s/.*average.*/`date`&/" -e "s/.*total.*/`date`&/" > /datarate/datarate.log
cat /datarate/datarate.log
output:
remotese01 130.326 Mbps
remotese02 99.1562 Mbps
Fri Aug 17 18:25:30 UTC 2018,remotese,remotese,229,total
Fri Aug 17 18:25:30 UTC 2018,remotese,remotese,114.7,average
server1101 219.804 Mbps
server1102 348.427 Mbps
Fri Aug 17 18:25:30 UTC 2018,server11,server11,568,total
Fri Aug 17 18:25:30 UTC 2018,server11,server11,284.1,average
------ Post updated at 01:50 PM ------
The reason that is ugly, because, i have 100 entries in my for loop..they have the same time stamp, unlike if i will embed the date within the awk,,each line will have diffrent time by seconds or minutes..
------ Post updated at 02:02 PM ------
New challenge.. New desired Output.. FInal..need help on this..
Fri Aug 17 18:25:30 UTC 2018,remotese01 130.326 Mbps
Fri Aug 17 18:25:30 UTC 2018,remotese02 99.1562 Mbps
Fri Aug 17 18:25:30 UTC 2018,remotese01,remotese,229,total
Fri Aug 17 18:25:30 UTC 2018,remotese02,remotese,114.7,average
Fri Aug 17 18:25:30 UTC 2018,server1101 219.804 Mbps
Fri Aug 17 18:25:30 UTC 2018,server1102 348.427 Mbps
Fri Aug 17 18:25:30 UTC 2018,server1101,server11,568,total
Fri Aug 17 18:25:30 UTC 2018,server1102,server11,284.1,average