[ale] awk fun
Geoffrey
lists at serioustechnology.com
Wed Apr 21 15:53:12 EDT 2010
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 }'
I think you want:
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
--
Until later, Geoffrey
"I predict future happiness for America if they can prevent
the government from wasting the labors of the people under
the pretense of taking care of them."
- Thomas Jefferson
More information about the Ale
mailing list