bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Help ourself


From: Tom Gray
Subject: Re: [bug-gawk] Help ourself
Date: Tue, 23 Apr 2019 21:21:43 +0000

Here's how I sort based on a specific field:

  {data[NR]=$0;
   sort_val[NR]=$1;  # pick any field for the numeric sort
  }

END {
   PROCINFO["sorted_in"]="@val_num_asc";
   for(i in sort_val) print data[i];
}

-----Original Message-----
From: bug-gawk <address@hidden> On Behalf Of david kerns
Sent: Tuesday, April 23, 2019 1:31 PM
To: Budi <address@hidden>
Cc: bug-gawk <address@hidden>
Subject: Re: [bug-gawk] Help ourself

[EXTERNAL]

oops, re-send w/ mail-list
probably the fastest/easiest is to use sort:
sort -n -k 1 f | awk ...

On Tue, Apr 23, 2019 at 11:56 AM Budi <address@hidden> wrote:

> How poor I'm.. my need is the opposite,
>
> is there a way to force such string lines, the 1st field  to be
> treated as number so can get sorted numerically only this field then
> stop doing it for the rest of characters at that line
>
>
> On 4/24/19, 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]