Recently had a conversation where someone needed help adding up the last column in a tab separated text file. It looked like a calling plan report. In channel tons of people brought up all sorts of *nix based tools which I thought odd since it was a Windows based IRC channel.
I've occasionally had a need for something like this anyway so poked at it for a few minutes and came up with the below one liner which I will leave here so my bad memory can find it again.
import-csv .\test.txt -Header "date","something","type","cost" -delimiter "`t" | Measure-Object cost -sum Count : 12 Average : Sum : 2.38 Maximum : Minimum : Property : cost
Since the text file doesn't have any header rows, you have to 'add them' through the import command.
Here is that test.txt file example.
14-Dec-11 0-234 Long Distance 0.32 14-Dec-11 0-960 Long Distance 0.04 09-Dec-11 1-237 Directory Assistance Call Comp 1.25 09-Dec-11 1-960 Directory Assistance Call Comp 0.15 22-Nov-11 0-234 Long Distance 0.12 22-Nov-11 0-960 Long Distance 0.01 16-Nov-11 0-234 Long Distance 0.16 16-Nov-11 0-960 Long Distance 0.02 12-Nov-11 0-234 Long Distance 0.20 12-Nov-11 0-960 Long Distance 0.02 11-Nov-11 0-234 Long Distance 0.08 11-Nov-11 0-960 Long Distance 0.01
Update:
A user (spade) in #PowerShell contributed this approach as well.
gc data2.txt | % {$sum=0} { $sum += ($_ -split "`t")[-1] } { $sum }