Solved

# Powershell aggregation of varying CSV Files to one CSV

Posted on 2010-08-17
964 Views
Hi,
I have a daily CSV File that is created but it content changes daily, it is basicly a mail count result.
I want to aggregate the CSV's that are created daily into one file weekly.

file on Sunday would look like this:

Alias, Count
Kevin,1
Jim,2
Roki,1

The file on monday would be :
Alias, Count
Roger,1
Jim, 4
Ralph,1

the weekly aggregated file would have need to look like this (note Jim with 6 mails as an aggregated count):
Alias, Count
Jim, 6
Kevin,1
Ralph,1
Roger,1
roki,1

I know how to aggregate  CSV's but how'd it be done powershell with files that change...
Thanks!
0
• 2

LVL 13

Accepted Solution

soostibi earned 500 total points
ID: 33452891
I would do this, assuming the files are agg1.txt, agg2.txt, etc. You can adjust the get-item part according to the actual filenames and path:
Get-Item c:\ee\agg*.txt | Import-Csv | Group-Object -Property alias |

Select-Object name,  @{n="sum"; e={(\$_.group | Measure-Object -Property count -Sum).sum}}

0

Author Comment

ID: 33453001
That works... its simple suddnly when its just writen like that :)
Thanks!!
0

Author Closing Comment

ID: 33453004
Thanks!
0

## Featured Post

This article will show, step by step, how to integrate R code into a R Sweave document
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …