Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Powershell aggregation of varying CSV Files to one CSV

Posted on 2010-08-17
Medium Priority
988 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
[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
• 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 following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
###### Suggested Courses
Course of the Month5 days, 20 hours left to enroll