Sponsored Content
Top Forums Shell Programming and Scripting awk or Bash: Cumulative average Post 302900716 by Akshay Hegde on Thursday 8th of May 2014 10:57:27 AM
Old 05-08-2014
Try something like this
Code:
$ awk '{print $1,(p+=$1)/NR}'  OFS='\t' file

Code:
$ cat file
546
344
1312
3234
1221
2322

Code:
$ awk '{print $1,(p+=$1)/NR,(str=str?str"+"$1:$1)"/"NR}' OFS='\t' file
546	546	546/1
344	445	546+344/2
1312	734	546+344+1312/3
3234	1359	546+344+1312+3234/4
1221	1331.4	546+344+1312+3234+1221/5
2322	1496.5	546+344+1312+3234+1221+2322/6


Last edited by Akshay Hegde; 05-08-2014 at 01:44 PM..
This User Gave Thanks to Akshay Hegde For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to average in awk

Hi, I have the data like this $1 $2 1 12 2 13 3 14 4 12 5 12 6 12 7 13 8 14 9 12 10 12 i want to compute average of $1 and $2 every 5th line (1-5 and 6-10) Please help me with awk Thank you (4 Replies)
Discussion started by: saint2006
4 Replies

2. Shell Programming and Scripting

Average in awk

Hi I am looking for an awk script which can compute average of all the fields every 5th line. The file looks: A B C D E F G H I J K L M 1 18 13 14 12 14 13 11 12 12 15 15 15 2 17 17 13 13 13 12 12 11 12 14 15 14 3 16 16 12 12 12 11 11 12 11 16 14 13 4 15 15 11 11 11 12 11 12 11... (6 Replies)
Discussion started by: saint2006
6 Replies

3. UNIX for Dummies Questions & Answers

Average in awk based on time

Hi I am looking for an awk script which can compute the average of the last column based on the date and time. The file looks: site1,"2000-01-01 00:00:00", "2000-01-01 00:59:00",0.013 site2,"2000-02-01 01:00:00", "2000-02-01 01:59:00",0.035 site1,"2000-02-01 02:00:00", "2000-02-01... (15 Replies)
Discussion started by: kathy wang
15 Replies

4. Shell Programming and Scripting

BASH. Need to extract some numbers and take the average

Hey all, I ran some simulations, of which the output is 100s of files. I've used grep to extract the vital information needed from the files. This has made my task somewhat easier. But I still need to perform some mathematical calculations (average and geometrical average) on the results of the... (9 Replies)
Discussion started by: slackjack
9 Replies

5. Shell Programming and Scripting

Calculate Average AWK

I want to calculate the average line by line of some files with several lines on them, the files are identical, just want to average the 3rd columns of those files.:wall: Example file: File 1 001 0.046 0.667267 001 0.047 0.672028 001 0.048 0.656025 001 0.049 ... (2 Replies)
Discussion started by: AriasFco
2 Replies

6. Shell Programming and Scripting

Calculating average with awk

I need to find the average from a file like: data => BW:123 M:30 RTD:0 1 0 1 0 0 1 1 1 1 0 0 1 1 0' data => BW:123 N:30 RTD:0 1 0 1 0 0 1 1 1 1 0 0 1 1 0' data => BW:123 N:30 RTD:0 1 0 1 0 0 1 1 1 1 0 0 1 1 0' data => BW:123 N:30 RTD:0 1 0 1 0 0 1 1 1 1 0 0 1 1 0' data => BW:123 N:30 RTD:0 1... (4 Replies)
Discussion started by: Slagle
4 Replies

7. UNIX for Dummies Questions & Answers

Calculating cumulative frequency using awk

Hi, I wanted to calculate cumulative frequency distribution of my data that involves several arithmetic calls. I did things in excel but its taking me forever. this is what I want to do: var1.txt contains n observations which I have to compute for frequency which is given by 1/n and subsequently... (7 Replies)
Discussion started by: ida1215
7 Replies

8. Shell Programming and Scripting

Bash script affect load average

Hello I have created next scritpt to do the next: chekp if host is alive. When the host down, launch telnet other equip to do checks. When execute the script the load average of the machines increase. For example: Before launch script top - 11:14:56 up 14 days, 18:06, 3 users, load... (3 Replies)
Discussion started by: capilla
3 Replies

9. Shell Programming and Scripting

Bash to calculate average of all files in directory and output by part of filename

I am trying to use awk to calculate the average of all lines in $2 for every file in a directory. The below bash seems to do that, but I cannot figure out how to capture the string before the _ as the output file name and have it be tab-delimeted. Thank you :). Filenames in... (3 Replies)
Discussion started by: cmccabe
3 Replies

10. Shell Programming and Scripting

awk Moving Average

Hi, I'm using awk to try and get a moving average for the second column of numbers ($2) in the below example broken out by unique identifier in column 1 ($1) : H1,1.2 H1,2.3 H1,5.5 H1,6.6 H1,8.7 H1,4.1 H1,6.4 H1,7.8 H1,9.6 H1,3.2 H5,50.1 H5,54.2 H5,58.8 H5,60.9 H5,54.3 H5,52.7... (8 Replies)
Discussion started by: theflamingmoe
8 Replies
dibbler-relay(8)						      Dibbler							  dibbler-relay(8)

NAME
dibbler-relay - a portable DHCPv6 relay DESCRIPTION
dibbler-relay is a portable implementation of the DHCPv6 relay. DHCPv6 relays are proxies, which allow one server to support links, which server is not directly connected to. There are ports available for Linux 2.4/2.6 systems as well as MS Windows XP and 2003. They are freely available under GNU GPL version 2 (or later) license. SYNOPSIS
dibbler-relay [ run | start | stop | status ] OPTIONS
run - starts relay in the console. Relay can be closed using ctrl-c. start - starts relay in daemon mode. stop - stops running relay. status - shows status of the relay. EXAMPLES
Relay forwards DHCPv6 messages between interfaces. Messages from client are encapsulated and forwarded as RELAY_FORW messages. Replies from server are received as RELAY_REPL message. After decapsulation, they are being sent back to clients. It is vital to inform server, where this relayed message was received. DHCPv6 does this using interface-id option. This identifier must be unique. Otherwise relays will get confused when they will receive reply from server. Note that this id does not need to be alligned with system interface id (ifindex). Think about it as "ethernet segment identifier" if you are using Ethernet network or as "bss identifier" if you are using 802.11 network. Let's assume this case: relay has 2 interfaces: eth0 and eth1. Clients are located on the eth1 network. Relay should receive data on that interface using well-known ALL_DHCP_RELAYS_AND_SERVER multicast address (ff02::1:2). Relay also listens on its global address 2000::123. Packets received on the eth1 should be forwarded on the eth0 interface, also using multicast address: log-level 8 log-mode short iface eth0 { server multicast yes } iface eth1 { client multicast yes client unicast 2000::123 interface-id 1000 } Here is another exmaple. This time messages should be forwarded from eth1 and eth3 to the eth0 interface (using multicast) and to the eth2 interface (using server's global address 2000::546). Also clients must use multicasts (the default approach): iface eth0 { server multicast yes } iface eth2 { server unicast 2000::456 } iface eth1 { client multicast yes interface-id 1000 } iface eth3 { client multicast yes interface-id 1001 } FILES
All files are created in the /var/lib/dibbler directory. During operation, Dibbler saves various file in that directory. Dibbler relay reads /etc/dibbler/relay.conf file. Log file is named client.log. STANDARDS
This implementation aims at conformance to the following standards: RFC 3315 DHCP for IPv6 RFC 3736 Stateless DHCPv6 BUGS
Bugs are tracked with bugzilla, available at http://klub.com.pl/bugzilla/. If you belive you have found a bug, don't hesitate to report it. AUTHOR
Dibbler was developed as master thesis on the Technical University of Gdansk by Tomasz Mrugalski and Marek Senderski. Currently Marek has not enough free time, so this project is being developed by Tomasz Mrugalski. Author can be reached at thomson@klub.com.pl. SEE ALSO
There are dibbler-server(8) and dibbler-client(8) manual pages available. You are also advised to take a look at project website located at http://klub.com.pl/dhcpv6/. As far as authors know, this is the only Windows DHCPv6 stateful implementation available and the only one with relay support. It is also one of two freely available under Linux. The other Linux implementation is available at http://dhcpv6.sourceforge.net, but it is rather outdated and seems not being actively developed. GNU
2004-12-11 dibbler-relay(8)
All times are GMT -4. The time now is 10:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy