How to sort using awk ?

Posted on 2009-02-24
Last Modified: 2012-05-06
I need to sort the following row using the awk. How can I sort using the third column in descending/ascending order ?

host6          22               11               11               no
host7          36               17               19               no
host7          41               23               18               no
host7          41               15               26               no
host7          61               20               41               no
host4          27               21               6                no
host4          12               11               1                no
Question by:beer9
    LVL 2

    Accepted Solution

    if you have access to "sort", the syntax is
    sort -k 3 -n -r

    -k 3 - for third field
    -n - for numeric sort
    -r - for descending

    Author Comment

    Thanks, it works for me! :)

    Author Closing Comment

    Thanks! :)

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
    I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to dynamically set the form action using jQuery.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now