?
Solved

AWK and Sort by field

Posted on 2004-12-01
6
Medium Priority
?
635 Views
Last Modified: 2013-12-26
I have  a large log file that has 18 fields in it,

Ex:

22-Nov-2004 01:35:54.44 tcp_in              Q 5 jcfaxhgibblyu@yyhmail.com rfc822;find@com find@com /mail/06/queue/tcp_in/002/ZR0I7Z00AF6W3UDF.00 <FYCQIMPNYZQGGRYOZKLQHMEM@wonet.com>  TCP active open: Failed connect()    Error: Connection refused


I want to forget about the fist 6 fields and do a sort by using the 7th field then print out how many times that the 7th field was duplicated in how many lines.


Thanks,






0
Comment
Question by:bt707
  • 2
  • 2
  • 2
6 Comments
 
LVL 13

Accepted Solution

by:
gripe earned 2000 total points
ID: 12719100
awk '{print $7}' your.log | sort | uniq -c
0
 

Author Comment

by:bt707
ID: 12719301

Thanks that worked, just what I wanted, had it almost right but that one little screw up always ruins everything,

One more question before I close this,

Is there a way to do this sort of field 7 and tell it to ignore a certain part of the value,  

Ex:

field 7 =   user@domain.com


I want to Ignore anything up to the @ and then sort with the remaining part of the feild

Ex:

user@domain.com   ignore the user  and then sort all of the field 7's user the rest  @domain.com

Thanks,
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 12719658
awk '{print $7}' your.log |awk -F@ '{print $2}' | sort | uniq -c

Wesly
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 38

Expert Comment

by:wesly_chen
ID: 12719670
awk '{print $7}' your.log |awk -F@ '{print "@"$2}' | sort | uniq -c
                                                            ^^^

Wesly
0
 
LVL 13

Expert Comment

by:gripe
ID: 12719824
awk -F@ '{print $3}' foo.txt | sort | uniq -c
0
 

Author Comment

by:bt707
ID: 12722035
Thanks gripe, that's what I needed, other answers looked good but you had already answered my original question, that's for the additional fix.


Thanks again,
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Screencast - Getting to Know the Pipeline
Suggested Courses

862 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