How to Sum the cost of similar products in Powershell2.0
hi,
i have text file below entries:-
product cost
television 500
laptop 300
modem 25
television 100
modem 35
laptop 700
how sum cost of similar products , write text file below? (should display
product name along sum)
product cost
television 600
laptop 1000
modem 60
tried “measure-object execcount –sum” gives sum of products. want individual sum of similar products. looks there no easy way in powershell.
thanks,
does any?
$hash = @{} get-content file.txt | foreach { if ($_ -match '(^.+?)\s+(\d+)'){ $hash[$matches[1]] += [int]$matches[2] } } $hash
update: had edit (replaced last line $hash)
the cold meds staring kick in, better quit now.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Windows Server > Windows PowerShell
Comments
Post a Comment