[ale] awk fun

Jim Kinney jim.kinney at gmail.com
Wed Apr 21 15:06:01 EDT 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20100421/6bc83bb6/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test
Type: application/octet-stream
Size: 4310 bytes
Desc: not available
Url : http://mail.ale.org/pipermail/ale/attachments/20100421/6bc83bb6/attachment.obj 


More information about the Ale mailing list