Last active
January 18, 2019 02:50
-
-
Save kpatnayakuni/dab0f1c99d34fc18f869451d93efe76e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$File = 'C:\Windows\Temp\delete.csv' | |
$Content = Get-Content -Path $File | |
<# File content | |
GroupA,GroupB,GroupC,1,2 | |
GroupB,GroupC,GroupD,1,2,3,4,5 | |
GroupA,GroupC,GroupE,1 | |
GroupA,GroupB,GroupE,1,2,3,4 | |
GroupC,GroupD,GroupE,1,2,3 | |
#> | |
foreach ($row in $Content) | |
{ | |
$rowvalues = $row.split(',') | |
$rowsum = ($rowvalues[3..$($rowvalues.Length)]|Measure-Object -Sum).Sum | |
($rowvalues[0..2] + $rowsum) -join ',' | |
} | |
<# Output | |
GroupA,GroupB,GroupC,3 | |
GroupB,GroupC,GroupD,15 | |
GroupA,GroupC,GroupE,1 | |
GroupA,GroupB,GroupE,10 | |
GroupC,GroupD,GroupE,6 | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment