![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to convert a single column into several rows and columns? | ashton_smith | UNIX for Dummies Questions & Answers | 5 | 05-24-2008 04:44 PM |
| convert rows into column | cdfd123 | Shell Programming and Scripting | 3 | 01-11-2008 12:54 PM |
| generate rows from date. | GrepMe | Shell Programming and Scripting | 14 | 08-24-2007 01:46 AM |
| splitting a column into rows | spindoctor | UNIX for Dummies Questions & Answers | 3 | 07-24-2007 03:25 PM |
| Factorize some rows in a column | frebo | UNIX for Dummies Questions & Answers | 5 | 03-21-2006 06:41 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Requesting an AWK code to generate averaged rows in a column
Hello,
I request your kind help in solving this problem... I have a file with two columns and "n" number of rows. For the first column, it won't be change. For the second column, I want to take the average of the first three rows. Then assign the averaged value to the first three rows. This process will be applied as well to the following 3 rows, after the changed rows. The output file will have two columns, the unchanged column ($1) and the changed column ($2). To illustrate the problem... Input file: $1= 1, 2, 3, 4, 5, 6.....n $2= 2, 4, 6, 8, 10, 12....n Output file: $1= no change $2= 4, 4, 4, 10, 10, 10....n (average of 2,4,6 is 4. average of 8,10,12 is 10) So far I have an AWK code that doesn't work: BEGIN {a[NR]=$2} { for (i=1;i<=n;i++) { avg=(a[i]+a[i+1]+a[i+2])/3; a[i]=avg; a[i+1]=avg; a[i+3]=avg; i=i+4; }; } END { i=1; while (i<=n) {print $1, a[i]; i+=1;}; } I'll appreciate a lot your help! Solracq |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|