Re: An interesting sort problem

2015-11-27 Thread Jon LaBadie
On Fri, Nov 27, 2015 at 09:57:11AM -0700, jd1008 wrote: > > > On 11/27/2015 03:29 AM, Andrew Haley wrote: > >#!/bin/awk -f > >{ > > lines[NR]=$NF " " $0 > >} > > > >END { > > PROCINFO["sorted_in"]="@val_type_asc" > ># for (i in lines) { for (i = NR; i >= 1; i--) { > >

Re: An interesting sort problem

2015-11-27 Thread jd1008
On 11/27/2015 12:14 PM, Jon LaBadie wrote: On Fri, Nov 27, 2015 at 09:57:11AM -0700, jd1008 wrote: On 11/27/2015 03:29 AM, Andrew Haley wrote: #!/bin/awk -f { lines[NR]=$NF " " $0 } END { PROCINFO["sorted_in"]="@val_type_asc" # for (i in lines) { for (i = NR; i

Re: An interesting sort problem

2015-11-27 Thread jd1008
On 11/27/2015 03:29 AM, Andrew Haley wrote: #!/bin/awk -f { lines[NR]=$NF " " $0 } END { PROCINFO["sorted_in"]="@val_type_asc" for (i in lines) { line = lines[i] j=index(line, " ") print substr(line, j+1) } } Hi Andrew, manpage for awk

Re: An interesting sort problem

2015-11-27 Thread jd1008
On 11/27/2015 01:28 PM, Jon LaBadie wrote: On Fri, Nov 27, 2015 at 12:38:38PM -0700, jd1008 wrote: On 11/27/2015 12:14 PM, Jon LaBadie wrote: On Fri, Nov 27, 2015 at 09:57:11AM -0700, jd1008 wrote: On 11/27/2015 03:29 AM, Andrew Haley wrote: #!/bin/awk -f { lines[NR]=$NF " " $0 }

Re: An interesting sort problem

2015-11-27 Thread Jon LaBadie
On Fri, Nov 27, 2015 at 12:38:38PM -0700, jd1008 wrote: > > > On 11/27/2015 12:14 PM, Jon LaBadie wrote: > >On Fri, Nov 27, 2015 at 09:57:11AM -0700, jd1008 wrote: > >> > >>On 11/27/2015 03:29 AM, Andrew Haley wrote: > >>>#!/bin/awk -f > >>>{ > >>> lines[NR]=$NF " " $0 > >>>} > >>> > >>>END

Re: An interesting sort problem

2015-11-27 Thread Andrew Haley
On 13/11/15 02:38, Michael Hennebry wrote: > Awk can do what you want: > { > lines[NR]=$NF " " $0 > } > > END { > PROCINFO["sorted_in"]="@val_type_asc" > for line in lines { > j=index(line, " ") > print substr(line, j+1) > } Close, but no cigar. #!/bin/awk -f {

Re: An interesting sort problem

2015-11-13 Thread jd1008
On 11/12/2015 07:38 PM, Michael Hennebry wrote: Awk can do what you want: { lines[NR]=$NF " " $0 } END { PROCINFO["sorted_in"]="@val_type_asc" for line in lines { j=index(line, " ") print substr(line, j+1) } Sorry, but, since this is being archived, could you

Re: An interesting sort problem

2015-11-13 Thread Robert Nichols
On 11/13/2015 12:32 PM, Ian Malone wrote: No missing quotes. It's an awk program, not a bash one, $0 is a bash variable. The only syntax errors I see are no brackets around the for statement and missing closing brace. My awk here is too old to support PROCINFO["sorted_in"], so here's a slight

Re: An interesting sort problem

2015-11-13 Thread Robert Nichols
On 11/13/2015 01:32 PM, Robert Nichols wrote: Try it again with more than 10 lines in the input. That asort() will be doing a _string_ sort, so with 120 input lines the order will be 1, 10, 100, 101, 102, ... 109, 11, 110, 111, 112, ... 119, 12, 120, 13, 14, ... 19, 2, 20, 21, ... . Sorry,

Re: An interesting sort problem

2015-11-13 Thread Ian Malone
On 13 November 2015 at 16:54, jd1008 wrote: > > > On 11/12/2015 07:38 PM, Michael Hennebry wrote: >> >> Awk can do what you want: >> { >> lines[NR]=$NF " " $0 >> } >> >> END { >> PROCINFO["sorted_in"]="@val_type_asc" >> for line in lines { >> j=index(line, "

Re: An interesting sort problem

2015-11-13 Thread Ian Malone
On 13 November 2015 at 18:32, Ian Malone wrote: > On 13 November 2015 at 16:54, jd1008 wrote: >> >> >> On 11/12/2015 07:38 PM, Michael Hennebry wrote: >>> >>> Awk can do what you want: >>> { >>> lines[NR]=$NF " " $0 >>> } > > No missing quotes. It's an

Re: An interesting sort problem

2015-11-13 Thread Patrick O'Callaghan
On Fri, 2015-11-13 at 09:54 -0700, jd1008 wrote: > I assume $0 is the name of the file ?? RTFM, awk(1) in this case. $0 refers to the whole input record (i.e. the current line), which is why fields are numbered from 1. I haven't looked at the rest of the script. poc -- users mailing list

Re: An interesting sort problem

2015-11-12 Thread Michael Hennebry
Awk can do what you want: { lines[NR]=$NF " " $0 } END { PROCINFO["sorted_in"]="@val_type_asc" for line in lines { j=index(line, " ") print substr(line, j+1) } -- Michael henne...@web.cs.ndsu.nodak.edu "Sorry but your password must contain an uppercase letter, a

Re: An interesting sort problem

2015-11-11 Thread Patrick O'Callaghan
On Wed, 2015-11-11 at 15:23 -0600, Bruno Wolff III wrote: > >How can one tell sort to chose the last word in the line as the sort > key? > > You can't. Field specifiers are relative to the start of the line. > There > isn't a way to specify them relative to the end of the line. In awk NF is the

Re: An interesting sort problem

2015-11-11 Thread jd1008
On 11/11/2015 04:44 PM, Patrick O'Callaghan wrote: On Wed, 2015-11-11 at 15:23 -0600, Bruno Wolff III wrote: How can one tell sort to chose the last word in the line as the sort key? You can't. Field specifiers are relative to the start of the line. There isn't a way to specify them

Re: An interesting sort problem

2015-11-11 Thread Patrick O'Callaghan
On Wed, 2015-11-11 at 16:58 -0700, jd1008 wrote: > > On 11/11/2015 04:44 PM, Patrick O'Callaghan wrote: > > On Wed, 2015-11-11 at 15:23 -0600, Bruno Wolff III wrote: > > > > How can one tell sort to chose the last word in the line as the > > > > sort > > > key? > > > > > > You can't. Field

Re: An interesting sort problem

2015-11-11 Thread Joe Wulf
: Bruno Wolff III <br...@wolff.to> To: jd1008 <jd1...@gmail.com> Cc: Fedora Community Users Support <users@lists.fedoraproject.org> Sent: Wednesday, November 11, 2015 4:23 PM Subject: Re: An interesting sort problem On Wed, Nov 11, 2015 at 13:54:50 -0700,   jd1008 <jd

Re: An interesting sort problem

2015-11-11 Thread Bruno Wolff III
On Wed, Nov 11, 2015 at 13:54:50 -0700, jd1008 wrote: The sort command does not provide for a way to say that the key is the last word in a line, where the file contains lines of varying number of words, and where words are groups of characters without spaces or tabs. Thus

An interesting sort problem

2015-11-11 Thread jd1008
The sort command does not provide for a way to say that the key is the last word in a line, where the file contains lines of varying number of words, and where words are groups of characters without spaces or tabs. Thus sort -k How can one tell sort to chose the last word in the line