thread count

Hi,

I have a log file in which there are plenty of threads. i want to count the number of unique threads.Here thread is tid value.
My Logfile looks like this--

Wed May 20 05:22:53.993 2009 Morocco Standard Time INFO:    pid 2172 tid 688: 17: 10106931: ArAuthFrameworkImpl::doPreAuth::1:10106931:: Authentication mechanism returned [0] for AuthIdentity []
Wed May 20 05:22:53.993 2009 Morocco Standard Time INFO:    pid 2172 tid 688: 170: 10106931: Arcot Native Server: recvd AA_BIN_MSG_VER_CHG
Wed May 20 05:22:57.634 2009 Morocco Standard Time INFO:    pid 2172 tid 3352: 170: 10106932: Arcot Native Server: recvd AA_BIN_MSG_GET_WLT
Wed May 20 05:22:57.634 2009 Morocco Standard Time INFO:    pid 2172 tid 3352: 170: 10106932: Session tracker Id associated with generate challenge[1:10106932]

Like this there are thousands of threads in a log file.
i want to capture the unique threads and count the numbers.
Any kind of help or suggestion will be very useful to me.

Thanks
NT

 awk 'BEGIN { FS1="[: ]+"}
{
        FS=FS1
        print $15
}' data > outfile

for tid in `cat outfile | /bin/sort -u`
do
        echo $tid appears `grep $tid outfile | wc -l` times.
done

perl -ne'
  / tid (\d+)/ && $tid{$1}++;
  print map "$_: $tid{$_}\n", keys %tid
    if eof
  ' infile

Try this:

awk '{a[$13]++}END{for(i in a){print i, a}}' file

Hi ,

i am using this code and it's giving me whole count including the repated ones. I just want to get the count of unique threads. please suggest me what i need to do to achieve this.

#!/usr/bin/perl -w

print "Hello, World...\n";
my $logFile = $ARGV[0]; 
die "usage: $0 <logFile>" unless $logFile; 
die "Logfile $logFile doesn't exist" unless -f "$logFile"; 
open(my $log, "<", $logFile) or die "Can't open $logFile for reading."; 
print "Processing file $logFile...\n"; 
#my $authenticates = {}; 
my $n = 0;
my $TIDCount = 0;
while(my $line = <$log>) { 
    # Outer loop. Look for an interesting part of the log file. 
	$n++; 
    $line =~ tr/\r\n//d; 
	if($line =~ /tid (\d+)/){
		$TIDCount++;
        next;
	}
}
print "Thread count for the logfile is $TIDCount\n";

thanks
NT

You should use something like this:

 ++$TIDcount 
    if / tid (\d+)/ && !$tidUnique{$1}++;

Given you sample data:

% perl -nle'
  ++$c if / tid (\d+)/ && !$tid{$1}++;
  print $c if eof
  ' infile
2

Borrowing from Franklin52:

awk '{a[$13]++}END{for(i in a) if (a==1) uniq++; print uniq }' file

Hi Radoulov,

what is $tidUnique here? how it is going to work in my case. Can you suggest me in my code.
when i used the code like this-

my $TIDCount = 0;
while(my $line = <$log>) { 
    # Outer loop. Look for an interesting part of the log file. 
	$n++; 
    $line =~ tr/\r\n//d; 
	++$TIDcount ;
    if /tid (\d+)/ && !$tidUnique{$1}++;
        next;
	
}
print "Thread count for the logfile is $TIDCount\n";

it gave me these errors
syntax error at tid_count.pl line 17, near "if /tid (\d+)/"
syntax error at tid_count.pl line 17, near "++;"
syntax error at tid_count.pl line 20, near "}"
Execution of tid_count.pl aborted due to compilation errors.

Thanks
NT

Try this:

#!/usr/bin/perl

use warnings;
use strict;

print "Hello, World...\n";

my $logFile = shift;
my ( $TIDCount, %TIDUnique );

die "usage: $0 <logFile>\n" unless defined $logFile;

die "Logfile $logFile doesn't exist\n" unless -f $logFile;

open my $log, $logFile or die "Can't open $logFile for reading\n";

print "Processing file $logFile...\n";

while (<$log>) {
    ++$TIDCount
      if / tid (\d+)/ && !$TIDUnique{$1}++;
}

print "Thread count for the logfile is $TIDCount\n";

Hi Radoulov,

Thank you very much, it worked for me.
I need to dig alot to learn perl.

Thanks
NT