candland

@candland rss self
May 8th 2007

Sum a column in a tab-delimited file using Powershell

Assuming you have a bunch of tab delimited files w/out headers and the second column as a number, you could use the following powershell command to sum the values and output the result.

PS > $sum=0; ls | cat | %{ $.split(“`t”)[1] } | %{ $sum+=[int]$ }; $sum
Sample File:
a-count    7
b-count 233
c-count 32

blog comments powered by Disqus