Sponsored Content
Top Forums Shell Programming and Scripting AWK - averaging $3 by info in $1 Post 302253195 by radoulov on Friday 31st of October 2008 06:58:50 AM
Old 10-31-2008
Use nawk or /usr/xpg4/bin/awk on Solaris.

Assuming you want to exclude the first line:

Code:
awk 'END {
  printf "%s %.2f %.2f\n", \
    n, v/c, s/c
  }      
!_[$1]++ && c { 
  printf "%s %.2f %.2f\n", \
    n, v/c, s/c
  c = 0    
  }
NR > 1 { 
  n = $1
  v = $2
  s += $3
  c ++
    }' infile

Given your data:

Code:
$ cat file
<name> <volume> <size>
a 2 1.2
a 2 1.1
b 3 1.7
c 0.7 1.9
c 0.7 1.9
c 0.7 1.8
$ awk 'END {
  printf "%s %.2f %.2f\n", \
    n, v/c, s/c
  }
!_[$1]++ && c {
  printf "%s %.2f %.2f\n", \
    n, v/c, s/c
  c = 0
  }
NR > 1 {
  n = $1
  v = $2
  s += $3
  c ++
    }' file
a 1.00 1.15
b 3.00 4.00
c 0.23 3.20

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

some info on awk please

i know this is a stupid question but...can awk do more than print? can i have it assign a value from a file list to a variable in the script? (1 Reply)
Discussion started by: MadHatter
1 Replies

2. Shell Programming and Scripting

averaging column values with awk

Hello. Im just starting to learn awk so hang in there with me...I have a large text file formatted as such everything is in a single column ID001 value 1 value 2 value....n ID002 value 1 value 2 value... n I want to be able to calculate the average for values for each ID from the... (18 Replies)
Discussion started by: johnmillsbro
18 Replies

3. UNIX for Dummies Questions & Answers

Averaging the rows using 'awk'

Dear all, I have the data in the following format. I want to do average of each NR= 5 (rows) for all the 3 ($1,$2, $3) columns and want to print average result in another file in the same format. I dont know how to write code for this in 'awk', can some one help me to write a code for this in... (1 Reply)
Discussion started by: arvindr
1 Replies

4. Shell Programming and Scripting

Averaging in increments using awk & head/tail

Hi, I only have a very limited understanding and experience with writing code and I was hoping I could get some help. I have a dataset of two columns (txt format, numbers in each row separated by a tab) Eg. 1 5 2 5 3 6 4 7 5 6 6 6 7 ... (5 Replies)
Discussion started by: Emred_Skye
5 Replies

5. Shell Programming and Scripting

Averaging data every 30 mins using AWK

A happy Monday to you all, I have a .csv file which contains data taken every 5 seconds. I want to average these 5 second data points into 30 minute averages! date co2 25/06/2011 08:04 8.31 25/06/2011 08:04 8.32 25/06/2011 08:04 8.33... (18 Replies)
Discussion started by: gd9629
18 Replies

6. Shell Programming and Scripting

Hourly averaging using Awk

Hey all, I have a set of 5-second data as shown below. I need to find an hourly average of this data. date co2 25/06/2011 08:04:00 8.30 25/06/2011 08:04:05 8.31 25/06/2011 08:04:10 8.32 25/06/2011 08:04:15 8.33 25/06/2011 08:04:20 ... (5 Replies)
Discussion started by: gd9629
5 Replies

7. Shell Programming and Scripting

Averaging help in awk

Hi all, I have a data file like below, where Time is in the second column DATE TIME FRAC_DAYS_SINCE_JAN1 2011-06-25 08:03:20.000 175.33564815 2011-06-25 08:03:25.000 175.33570602... (10 Replies)
Discussion started by: gd9629
10 Replies

8. Shell Programming and Scripting

Loop for row-wise averaging of multiple files using awk

Hello all, I need to compute a row-wise average of files with a single column based on the pattern of the filenames. I really appreciate any help on this. it would just be very difficult to do them manually as the rows are mounting to 100,000 lines. the filenames are as below with convention as... (2 Replies)
Discussion started by: ida1215
2 Replies

9. Shell Programming and Scripting

How to perform averaging of values for particular timestamp using awk or anythoing else??

I have a file of the form. 16:00:26,83.33 16:05:26,83.33 16:10:26,83.33 16:15:26,83.33 16:20:26,90.26 16:25:26,83.33 16:30:26,83.33 17:00:26,83.33 17:05:26,83.33 17:10:26,83.33 17:15:26,83.33 17:20:26,90.26 17:25:26,83.33 17:30:26,83.33 For the timestamp 16:00:00 to 16:55:00, I need to... (5 Replies)
Discussion started by: Saidul
5 Replies

10. Shell Programming and Scripting

Help with awk to extract additional info

Hi I use multipath linux command to get LUNs info and find out if any failed. # multipath -ll >/tmp/mpfail # cat /tmp/mpfail multipath.conf line 109, invalid keyword: user_friendly_names multipath.conf line 153, invalid keyword: user_friendly_names multipath.conf line 193, invalid... (4 Replies)
Discussion started by: prvnrk
4 Replies
g_disre(1)					 GROMACS suite, VERSION 4.5.4-dev-20110404-bc5695c					g_disre(1)

NAME
g_disre - analyzes distance restraints VERSION 4.5.4-dev-20110404-bc5695c SYNOPSIS
g_disre -s topol.tpr -f traj.xtc -ds drsum.xvg -da draver.xvg -dn drnum.xvg -dm drmax.xvg -dr restr.xvg -l disres.log -n viol.ndx -q viol.pdb -c clust.ndx -x matrix.xpm -[no]h -[no]version -nice int -b time -e time -dt time -[no]w -xvg enum -ntop int -maxdr real -nlevels int -[no]third DESCRIPTION
g_disre computes violations of distance restraints. If necessary, all protons can be added to a protein molecule using the g_protonate program. The program always computes the instantaneous violations rather than time-averaged, because this analysis is done from a trajectory file afterwards it does not make sense to use time averaging. However, the time averaged values per restraint are given in the log file. An index file may be used to select specific restraints for printing. When the optional -q flag is given a .pdb file coloured by the amount of average violations. When the -c option is given, an index file will be read containing the frames in your trajectory corresponding to the clusters (defined in another manner) that you want to analyze. For these clusters the program will compute average violations using the third power averaging algorithm and print them in the log file. FILES
-s topol.tpr Input Run input file: tpr tpb tpa -f traj.xtc Input Trajectory: xtc trr trj gro g96 pdb cpt -ds drsum.xvg Output xvgr/xmgr file -da draver.xvg Output xvgr/xmgr file -dn drnum.xvg Output xvgr/xmgr file -dm drmax.xvg Output xvgr/xmgr file -dr restr.xvg Output xvgr/xmgr file -l disres.log Output Log file -n viol.ndx Input, Opt. Index file -q viol.pdb Output, Opt. Protein data bank file -c clust.ndx Input, Opt. Index file -x matrix.xpm Output, Opt. X PixMap compatible matrix file OTHER OPTIONS
-[no]hno Print help info and quit -[no]versionno Print version info and quit -nice int 19 Set the nicelevel -b time 0 First frame (ps) to read from trajectory -e time 0 Last frame (ps) to read from trajectory -dt time 0 Only use frame when t MOD dt = first time (ps) -[no]wno View output .xvg, .xpm, .eps and .pdb files -xvg enum xmgrace xvg plot formatting: xmgrace, xmgr or none -ntop int 0 Number of large violations that are stored in the log file every step -maxdr real 0 Maximum distance violation in matrix output. If less than or equal to 0 the maximum will be determined by the data. -nlevels int 20 Number of levels in the matrix output -[no]thirdyes Use inverse third power averaging or linear for matrix output SEE ALSO
gromacs(7) More information about GROMACS is available at <http://www.gromacs.org/>. Mon 4 Apr 2011 g_disre(1)
All times are GMT -4. The time now is 11:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy