replying to myself as I figured out that the one-liner was just plain broken.<br><br>cat test | awk '{ s = s + NF }; END { print s }'<br><br>works as desired. And matched output from wc -w<br><br><div class="gmail_quote">
On Wed, Apr 21, 2010 at 3:06 PM, Jim Kinney <span dir="ltr"><<a href="mailto:jim.kinney@gmail.com">jim.kinney@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I was testing an awk one-liner and hit one that doesn't work. <br><pre>awk '{ s = 0; for (i = 1; i <= NF; i++) s = s+$i; print s }'<br><br>should return the number of word/field per line. I haven't tinkered with the FS setting. the file I'm testing on is an ipsolorum I generated days ago. It's at the bottom of this email.<br>
<br>When I test the values I should get with:<br>grep -o " " test| grep -c " "<br>where test has the ipsolorum text I get 626 which, without actually counting seems OK if not a bit high.<br><br>But the awk returns:<br>
0<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>0<br>12<br>0<br>0<br>0<br><br><br>Correct # of lines but totally crap number of words.<br><br><br><br><br></pre><br clear="all"><br>-- <br><font color="#888888">-- <br>
James P. Kinney III<br>
Actively in pursuit of Life, Liberty and Happiness <br><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>-- <br>James P. Kinney III<br>Actively in pursuit of Life, Liberty and Happiness <br><br>