[ale] awk fun

Jim Kinney jim.kinney at gmail.com
Wed Apr 21 16:14:37 EDT 2010


bozo me. The self-reply was after I had merged the broken one-liner with the
next broken one-liner and fixed both.

Yes, the $i was a fubar. But my run gave really strange results:
5778
0
4753
105
378
0
3486
0
5460
0
5253
0
3570
105
0
1
which looks like FS = NULL

print NF is correct as it does the "RightThing". William was right.

On Wed, Apr 21, 2010 at 3:53 PM, Geoffrey <lists at serioustechnology.com>wrote:

> 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
> _______________________________________________
> 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
>



-- 
-- 
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/350f14f3/attachment.html 


More information about the Ale mailing list