bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Help ourself


From: arnold
Subject: Re: [bug-gawk] Help ourself
Date: Wed, 24 Apr 2019 05:13:09 -0600
User-agent: Heirloom mailx 12.5 7/5/10

This is correct. When the input line has a single numeric value,
gawk turns it into a number. With multiple values, the line is treated
as a string.

Arnold

david kerns <address@hidden> wrote:

> awk is not strongly typed ... variables are what you coerce them into being.
> In the first example you assigned "a" pure numeric values.
> In the second example you assigned "a" all strings (each value contains 2
> spaces)
> change your first example to this:
>
> awk '{a[NR]=$0 ""}END{ asort(a);for(;i++<NR;){ print a[i] }}' f
>
> and it will string sort too
>
> On Tue, Apr 23, 2019 at 9:41 AM Budi <address@hidden> wrote:
>
> > We have facts that
> > $ export LC_ALL=C
> >
> > $ cat f
> > 2161
> > 4321
> > 6481
> > 8641
> > 10801
> > 4321
> > 8641
> > 12961
> > 17281
> > 21601
> >
> > $ awk '{a[NR]=$0}END{ asort(a);for(;i++<NR;){ print a[i] }}' f
> > 2161
> > 4321
> > 4321
> > 6481
> > 8641
> > 8641
> > 10801
> > 12961
> > 17281
> > 21601
> >
> > One would accept as it's a number sort
> >
> > $ cat f
> > 36829.00 37145.00 2161
> > 36829.00 37145.00 4321
> > 36829.00 37145.00 6481
> > 36829.00 37145.00 8641
> > 36829.00 37145.00 10801
> > 36829.00 37145.00 4321
> > 36829.00 37145.00 8641
> > 36829.00 37145.00 12961
> > 36829.00 37145.00 17281
> > 36829.00 37145.00 21601
> >
> >
> > $ awk '{a[NR]=$0}END{ asort(a);for(;i++<NR;){ print a[i]}}' f
> > 36829.00 37145.00 10801
> > 36829.00 37145.00 12961
> > 36829.00 37145.00 17281
> > 36829.00 37145.00 21601
> > 36829.00 37145.00 2161
> > 36829.00 37145.00 4321
> > 36829.00 37145.00 4321
> > 36829.00 37145.00 6481
> > 36829.00 37145.00 8641
> > 36829.00 37145.00 8641
> >
> > One would accept as it's a string sort
> >
> > How to resolve this confusing processes ?
> >
> >



reply via email to

[Prev in Thread] Current Thread [Next in Thread]