AWK command & SORT

Posted on 2004-11-30
Last Modified: 2013-12-27
I have a command I use like this:

awk ' /refused/ {print $6, $7, $16, $17,$18}' log_file1 | sort | uniq -c

It works fine but when it prints out each line with the number of times that line occured in the file I want it to do a sort on the number of times it occured in the file.
I want the ones that occured in the file the most to be on top and sorted desending down, I wanted to pipe this command back to sort but can't find a way to sort
the number of occurances, I'm sure this can be done but can't find a way to do it.

Question by:bt707
    LVL 13

    Accepted Solution

    Just append:

    awk ' /refused/ {print $6, $7, $16, $17,$18}' log_file1 | sort | uniq -c | sort -nr
    LVL 38

    Expert Comment

    Put -nr for sort:
    awk ' /refused/ {print $6, $7, $16, $17,$18}' log_file1 | sort -nr | uniq -c

    LVL 38

    Expert Comment

    Oops, gripe just got it.


    Author Comment

    Thanks gripe, that's what i was looking for.

    Thanks again

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
    In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    761 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

    14 Experts available now in Live!

    Get 1:1 Help Now