Re: An interesting sort problem

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

 



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 tweak using asort:

awktest:
----
{
     lines[NR]=$NF " " $0
}

END {
     #PROCINFO["sorted_in"]="@val_type_asc"
     asort(lines, ordered)
     for (ind = 1 ; ind<=length(ordered) ; ind++) {
        line=ordered[ind]
        j=index(line, " ")
        print substr(line, j+1)
     }
}
----

awktestinput:
----
Friday Lemon abc xyz
Saturday cucumber cool
Sunday orange citrussy
Monday apple computer
----

$ awk -f awktest  < awktestinput
Sunday orange citrussy
Monday apple computer
Saturday cucumber cool
Friday Lemon abc xyz

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, ... .

--
Bob Nichols     "NOSPAM" is really part of my email address.
                Do NOT delete it.

--
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux