Learn how to a build a cloud-first strategyRegister Now


AWK command & SORT

Posted on 2004-11-30
Medium Priority
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
  • 2
LVL 13

Accepted Solution

gripe earned 2000 total points
ID: 12711636
Just append:

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

Expert Comment

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

LVL 38

Expert Comment

ID: 12711738
Oops, gripe just got it.


Author Comment

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

Thanks again

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month20 days, 20 hours left to enroll

810 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