awk command

Posted on 2004-11-30
Last Modified: 2013-12-27
I have a very large log file and need to find all lines with a certain statement in it, there is many of them repeating, I need to get it to work with and without uniq lines.

here is a example of one of the lines I'm looking for,    the key that is in each line is  ( Connection refused )

30-Nov-2004 08:20:05.76 tcp_intranet              Q 8 rfc822; /opt/iplanet/ms5/msg-hampton/queue/tcp_intranet/005/Z60I7W00.00 <> mailsrv  TCP active open: Failed connect()    Error: Connection refused

I can find these lines with grep but I want to find these lines and only print the columns  5 and 6 and the   Error: Connection refused

Question by:bt707

    Author Comment

    also is there a way to use uniq and only print out one line of all the duplicate lines but get a number of how many times a duplicate line was in the file.


    Author Comment


    I have it about working using this

    awk '$18 ~ /refused/ {print $6, $7, $16, $17,$18}' log_files | uniq

    however i'm still for a way to print to screen one copy of the duplicate lines but get a number of how many times the duplicate lines was in the file,

    any sugestions,

    LVL 20

    Accepted Solution

    Does this do what you want?
    awk '$18 ~ /refused/ {print $6, $7, $16, $17,$18}' log_files |sort |uniq -c

    Author Comment

    Thanks tfewster worked Great,

    Thanks again,

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
    Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap ( Version 1.2 2.      Jpcap( Version 0.6 Prerequisite: 1.      GCC …
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    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.

    754 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

    18 Experts available now in Live!

    Get 1:1 Help Now