 <p>Not quite one line, but will work</p> <pre class="lang-none prettyprint-override"><code>$ cat votes.txt Colorado Obama 50 Colorado Romney 20 Colorado Gingrich 30 Florida Obama 60 Florida Romney 20 Florida Gingrich 30 </code></pre> <p>script</p> <pre><code>while read loc can num do if ! [ ${!can} ] then cans+=($can) fi (( $can += num )) done &lt; votes.txt for can in ${cans[*]} do echo $can ${!can} done </code></pre> <p>output</p> <pre class="lang-none prettyprint-override"><code>Obama 110 Romney 40 Gingrich 60 </code></pre>