[ale] awk fun

Jim Kinney jim.kinney at gmail.com
Wed Apr 21 15:54:04 EDT 2010


replying to myself as I figured out that the one-liner was just plain
broken.

cat test | awk '{  s = s + NF }; END { print s }'

works as desired. And matched output from wc -w

On Wed, Apr 21, 2010 at 3:06 PM, Jim Kinney <jim.kinney at gmail.com> wrote:

> I was testing an awk one-liner and hit one that doesn't work.
>
> awk '{ s = 0; for (i = 1; i <= NF; i++) s = s+$i; print s }'
>
> 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.
>
> When I test the values I should get with:
> grep -o " " test| grep -c " "
> where test has the ipsolorum text I get 626 which, without actually counting seems OK if not a bit high.
>
> But the awk returns:
>
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 0
> 12
> 0
> 0
> 0
>
>
> Correct # of lines but totally crap number of words.
>
>
>
>
>
>
> --
> --
> James P. Kinney III
> Actively in pursuit of Life, Liberty and Happiness
>
>


-- 
-- 
James P. Kinney III
Actively in pursuit of Life, Liberty and Happiness
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20100421/b1534df6/attachment-0001.html 


More information about the Ale mailing list