[ale] awk fun
William Miller
smeadspam100 at gmail.com
Wed Apr 21 15:49:30 EDT 2010
Jim,
Have you tried the following?
awk '{print NF}' test
That yielded the following for me:
107
0
97
14
27
0
83
0
104
0
102
0
84
14
0
1
Wiliam
On 04/21/2010 03:06 PM, Jim Kinney 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
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20100421/5cf6428a/attachment.html
More information about the Ale
mailing list