![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Averaging segments and including the name
Hello, I have a awk line that averages rows. So if my file looks like this: Code:
Jack 1 1 1 1 1 1 Joe 1 1 1 1 1 1 Jerry 0 0 0 0 0 0 John 1 1 1 0 0 0 The awk line below skips column 1 and then averaged the rows Code:
awk -F'\t' -v r=3 '{for(i=r+1;i<=NF;i+=r){for(j=0;j<r;j++){sum+=$(i-j)}printf "%s ", sum/r;sum=0}; printf "\n"}'
The end product looks like this Code:
1 1 1 1 0 0 1 0 Basically what I want to do is print the first column as well... (the names) So the end product will look like this: Code:
Jack 1 1 Joe 1 1 Jerry 0 0 John 1 0 what modifications do I need to make? thanks
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Averaging | Muhammad Rahiz | UNIX for Dummies Questions & Answers | 2 | 11-12-2009 06:00 AM |
| Averaging multiple columns | gisele_l | Shell Programming and Scripting | 4 | 10-18-2009 06:53 PM |
| Averaging segments | kylle345 | Shell Programming and Scripting | 11 | 09-16-2009 01:04 PM |
| averaging column values with awk | johnmillsbro | Shell Programming and Scripting | 18 | 01-26-2009 01:20 PM |
| AWK - averaging $3 by info in $1 | itisthus | Shell Programming and Scripting | 3 | 11-03-2008 06:12 AM |