Solved

perl or shell to sum columns 2-6 into a single column 2, create 3rd column 12 month binned avg

Posted on 2012-03-16
2
390 Views
Last Modified: 2012-06-27
See attached input file.

assuming the file perl file is called aceavg.pl or the shell script file is called aceavg.sh and creates an output file called aceavg.txt and I want to called the the script by either

perl aceavg.pl > aceavg.txt

or

sh aceavg.sh > aceavg.txt

I want to use the input file found at /path/ace.txt and simply do 2 things. 1st, sum columns 2-6 into a single column 2. 2nd, I want to create a 3rd column with 12 month rolling binned averages. So the third column won't start until month 12 since 12 data points are needed so rows 1-11 will only have two columns of data and the 3rd column of data begins from row 12. See input file.
ace.txt
0
Comment
Question by:libertyforall2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
ID: 37732512
This script test script that sums that columns you need.  If you explain how you need the binned average, I would be in a position to give you the remaining part.  Try running this:


#!/usr/bin/perl

use warnings;
use strict;

my @dat = grep {/\d\d\/\d\d\/\d{4}/} <>;
my @vals;
foreach my $row (@dat)
{
    my @col = split(/ /, $row);
    my $sum = 0;
    $sum  += $col[$_] for (1..5);
    push (@vals,"$col[0] $sum");
}
$" = "\n";
print "@vals", "\n";

Open in new window

0
 

Author Closing Comment

by:libertyforall2
ID: 37780013
Issue resolved.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question