average value


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers average value
# 1  
Old 03-10-2007
average value

If I have a file like this, could anyone please guide me how to find the average value in each metrix. The file has got about 130,000 metrixs.

Grid-ref= 142, 235
178 182 203 240 273 295 289 293 283 262 201 176
167 187 187 246 260 282 299 312 293 276 230 191
169 195 213 239 286 291 290 276 300 278 215 197
157 163 188 225 271 282 297 283 281 268 208 186
182 167 192 237 248 276 308 279 276 264 229 187
161 163 204 230 288 303 295 279 281 245 217 178
154 185 224 231 260 288 292 285 291 263 213 169
170 186 187 217 261 300 288 278 270 247 192 172
189 170 187 237 264 286 300 305 283 251 226 173
171 186 192 219 265 291 287 290 278 238 216 192
Grid-ref= 142, 236
159 166 186 226 260 285 281 274 267 240 186 157
151 179 172 233 252 276 287 297 276 253 211 172
150 182 196 225 274 285 281 272 283 256 195 176
138 148 172 210 259 284 291 270 266 246 191 171
169 144 183 222 246 278 290 263 259 241 214 167
145 152 190 219 276 283 279 266 264 230 203 158
151 179 216 215 256 281 277 271 274 244 204 156
154 171 174 203 248 291 274 263 264 240 169 154
174 154 176 228 257 276 284 291 266 234 216 151
147 175 173 206 256 285 272 273 260 221 200 179
Grid-ref= 142, 237
133 142 157 193 228 259 249 245 239 212 157 132
124 154 142 202 221 252 258 270 249 225 183 151
125 160 167 192 244 256 253 240 254 226 166 146
109 121 143 180 228 259 264 240 237 219 160 146
145 120 154 192 214 249 262 234 228 212 184 141
118 126 164 191 249 257 253 237 240 202 177 133
126 156 190 184 225 254 250 241 249 218 177 133
131 151 149 175 218 269 247 234 236 212 148 129
147 129 150 203 230 250 258 263 238 206 191 128
121 153 152 183 232 261 246 246 233 191 172 151

I wanna get the output as shown below
Grid-ref= 142, 235
169.8 178.4 197.7 232.1 267.6 289.4 294.5 288 283.6 259.2 214.7 182.1
Grid-ref= 142, 236
153.8 165 183.8 218.7 258.4 282.4 281.6 274 267.9 240.5 198.9 164.1
Grid-ref= 142, 237
127.9 141.2 156.8 189.5 228.9 256.6 254 245 240.3 212.3 171.5 139

Any idea would be greatly appreciated.
su_in99
# 2  
Old 03-10-2007
# 3  
Old 03-10-2007
nawk -f grid.awk myMatrixFile

grid.awk:
Code:
function outputGrid(i) {
  printf("%s\n", thisGrid)
  for(i=1; i<= col; i++)
     printf("%.1f%s", arr[i]/row, (i==col) ? RS : OFS)

  thisGrid=$0
  split("", arr)
  row=0
}

/^Grid/ {
  ( thisGrid != "") ? outputGrid() : thisGrid=$0
  next
}

/^[0-9][0-9]*/ {
  row++
  col=NF
  for(i=1; i <= NF; i++) {
    arr[i] += $i
  }
}
END {
  outputGrid()
}


Last edited by vgersh99; 03-10-2007 at 01:52 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get average and percentage non zero value

How to calculate percentage non zero value occurrence base on value col 1 and 2 2017 a 0 2017 a 2 2017 a 4 2017 a 2 2017 a 0 2017 b 2 2017 b 6 2016 a 2 2016 a 2 2016 b 2 2016 b 8 2016 b 0 2016 b 0 2016 c 2 2016 c 2 2016 c 0 i manage to get average # awk '{A++;B+=$3}END{for(X in... (1 Reply)
Discussion started by: before4
1 Replies

2. Shell Programming and Scripting

Finding an average

Basically, I need to find average of numbers which are given like: sh average file1 file (in files can be more than one number) ->10 sh average 5 7 ->6 sh average /users/file ->5 echo 5 7 | sh average 6 So basically i wrote my code but it gives me error... I am pretty sure it has to work... (10 Replies)
Discussion started by: Manu1234567
10 Replies

3. Shell Programming and Scripting

Get column average using ID

I have a file that looks like this: id window BV 1 1 0.5 1 2 0.2 1 3 0.1 2 1 0.5 2 2 0.1 2 3 0.2 3 1 0.4 3 2 0.6 3 3 0.8 Using awk, how would I get the average BV for window 1? Output like this: window avgBV 1 0.47 2 0.23 (10 Replies)
Discussion started by: jwbucha
10 Replies

4. Shell Programming and Scripting

Find the average and the different

Hi , Every day I'll get a file, in that I have to match today's file(20130619) third column to previous files (20130618,20130617), that is 124 present in previous files or not. If it matches then I have take the average values of 5th column of 124 from yesterdays and day before yesterdays file,... (5 Replies)
Discussion started by: Shenbaga.d
5 Replies

5. Shell Programming and Scripting

Loop for average

I am trying to write a loop script in bash thru umbuntu for the following: ask for a password if wrong show a message if wright then asks for 3 numbers from you then calculates the average of them at the end it saves the average and the date of the calculation in a text file and then zips it.... (1 Reply)
Discussion started by: redmond1212
1 Replies

6. UNIX for Dummies Questions & Answers

Calculating average

Hi, i have 12 float variables in a bash file and i want to calculate the average of them. Can any body help? (6 Replies)
Discussion started by: limadario
6 Replies

7. Shell Programming and Scripting

How to static the average value

Hi all, Sorry I make a mistake,the title should be "How to statistic the average value " I do five times about "mv 123 to 456" and do five times about "mv 456 to 123" As we know,"time" can get the real usr sys value, I want to get the average real,usr,sys of "mv 123 to 456" and "mv 456 to... (4 Replies)
Discussion started by: yanglei_fage
4 Replies

8. 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

9. 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

10. Shell Programming and Scripting

count average

Hi Friends, Can any one help me with count average of student marks in this file (i can not change structure of the input file): input file: 1:John Smith:2 3 4 5 2:Mark Anderson:3 2 3:Susan Waterman:2 4 2 (numbers of marks are different) output: Name:John Smith ID#: 1 Avg. mark:... (6 Replies)
Discussion started by: mleplawy
6 Replies
Login or Register to Ask a Question