Go Premium for a chance to win a PS4. Enter to Win

x
Solved

# Powershell aggregation of varying CSV Files to one CSV

Posted on 2010-08-17
Medium Priority
1,008 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 2000 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

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Loops Section Overview
###### Suggested Courses
Course of the Month8 days, 21 hours left to enroll