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 ------
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
}
{ cmd = system("date") }
END { print_total()
}'
output:
Code:
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
Code:
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:
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:
Code:
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..
Code:
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
Last edited by kenshinhimura; 08-17-2018 at 01:55 PM..
Hi, I've written a shell function in bash that reads letters into an array, then outputs them in one column with:
for n in "${array}"; do
echo $n
done
I was wondering if anyone knew how i would transpose the letters that are output by the for loop. Right now my output is:
aabbcc... (4 Replies)
Hi,
I need to remove all lines from a file that do not start with numbers
For instance, if the first three characters on any line are not numbers, delete those lines
I've tried to do it with awk and it's not working, any ideas ?
Thanks (5 Replies)
I want to add letters A,B,C,… in front of every line of input while printing them out using PERL.
eg
A file is parsed as a cmd line arg and its context will be displayed as
A line1...
B line 2..
I tried this..but I want better and perfect solution!
!perl -p
my $counter;
BEGIN { $counter... (4 Replies)
Hello,
I am working with a perl script that tries to find the average "frequency" in which lines are duplicated. So far I've only managed to find the way to count how many times the lines are repeated, the code is as follows:
perl -ae'
my $filename= $ENV{'i'};
open (FILE, "$filename") or... (10 Replies)
I'm reading in numbers from a file and trying to add them together. Here is the code so far. I know the 1+2+3.... part is wrong. The file has five numbers in it with each number on its own line. The numbers are decimals if that matters. Thanks.
while read EachLine
do
echo $EachLine
done <... (6 Replies)
Hi,
Is there a tool somewhat parallel to rev, but which randomizes instead of reverses?
I've tried rl, but I can only get it to randomize words.
I was hoping for something like this
echo "hello" | ran
leolh
less simpler solutions are also welcome.
Sorry if the question is... (21 Replies)
Hi there,
first of all this is not homework...this is a new type of exercise for practicing vocabulary with my students.
I have a file consisting of two columns, separated by a tab, each line consisting of a word and its definition, separated by a line break.
What i need is to replace a... (15 Replies)
The awk below executes and is close (producing the first 4 columns in desired). However, when I add the sum of $7, I get nothing returned. Basically, I am trying to combine all the matching $4 in f1 and output them with the average of $7 in each match. Thank you :).
f1
... (2 Replies)