The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Count first column on the basis of two other columns kaustubh137 Shell Programming and Scripting 1 05-29-2008 09:54 AM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 09:57 AM
How to count pattern in column ahjiefreak Shell Programming and Scripting 12 12-04-2007 07:53 PM
How to count the record count in an EBCDIC file. oracle8 UNIX for Dummies Questions & Answers 1 07-26-2006 08:22 PM
Max column count in a file gemini Shell Programming and Scripting 2 08-24-2004 01:12 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-27-2008
gobinath gobinath is offline
Registered User
  
 

Join Date: May 2008
Posts: 8
How to get the count only if two column matches?

Hi,

I have a file with the contents as below,

Code:
10:23:10        GOOD      10.30.50.60
10:23:11        GOOD      10.30.50.62
10:23:12        Hello        10.30.50.60
10:23:12        BAD         10.30.50.60
10:23:13        GOOD       10.30.50.66
10:23:14        BAD         10.30.50.62
10:23:15        Hello        10.30.50.66
10:23:16        Hello        10.30.50.66
10:23:16        BAD         10.30.50.66

I need the output like this,

Code:
No of Hello for  10.30.50.60: 1
No of Hello for  10.30.50.66: 2

Also

Code:
No of Hello for 10:23 (time) : 3

Please anyone suggest a script for this.

Thanks in advance

Last edited by Yogesh Sawant; 05-27-2008 at 04:29 AM.. Reason: added code tags
  #2 (permalink)  
Old 05-27-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 167

Code:
$ awk '$2=="Hello" {count["Number of "$2" for "$3]++}END{for(j in count) print j":",count[j]}' gobi1.txt
Number of Hello for 10.30.50.60: 1
Number of Hello for 10.30.50.66: 2

//Jadu
  #3 (permalink)  
Old 05-27-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 167
And,


Code:
$ awk '$2=="Hello" {count["Number of "$2" for "substr($1,1,5)]++}END{for(j in count) print j"(time):",count[j]}' gobi1.txt
Number of Hello for 10:23(time): 3

//Jadu
  #4 (permalink)  
Old 05-27-2008
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Or:

Code:
awk '{a[$4 " in " $5]++
      b[$4" for "$1":"$2]++;next}
END{
for ( i in a )
   print "No of "i":" a[i]
print "---------------------------"
for ( i in b )
   print "No of "i"(time):" b[i]

}' FS="( )|(:)"file
No of GOOD in 10.30.50.60:1
No of GOOD in 10.30.50.62:1
No of GOOD in 10.30.50.66:1
No of BAD in 10.30.50.60:1
No of Hello in 10.30.50.60:1
No of BAD in 10.30.50.62:1
No of BAD in 10.30.50.66:1
No of Hello in 10.30.50.66:2
---------------------------
No of Hello for 10:23(time):3
No of BAD for 10:23(time):3
No of GOOD for 10:23(time):3

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0