Hi Perl guru's

My name is ABHI and i am almost new on perl i need help for below mentioned issue.

Well,

I have one file(xyz.txt) containing following text

LT19-10-13-400922 --TID1-3039@10.100.14.163 1--RequestREGISTER
LT19-10-13-405432 --TID1-3039@10.100.14.163 1--Response100
LT19-10-13-410015 --TID1-3039@10.100.14.163 1--Response401
LT19-10-13-415481 --TID1-3039@10.100.14.163 2--RequestREGISTER
LT19-10-13-419800 --TID1-3039@10.100.14.163 2--Response100
LT19-10-13-426400 --TID2-3039@10.100.14.163 1--RequestREGISTER
LT19-10-13-463320 --TID3-3039@10.100.14.163 1--RequestREGISTER
LT19-10-13-514112 --TID4-3039@10.100.14.163 1--RequestREGISTER
LT19-10-13-519524 --TID1-3039@10.100.14.163 2--Response200
LT19-10-13-524129 --TID2-3039@10.100.14.163 1--Response100
LT19-10-13-528946 --TID2-3039@10.100.14.163 1--Response401
LT19-10-13-534280 --TID2-3039@10.100.14.163 2--RequestREGISTER
LT19-10-13-538468 --TID3-3039@10.100.14.163 1--Response100
LT19-10-13-543036 --TID3-3039@10.100.14.163 1--Response401
......................................
..........................................
LT19-11-23-201675 --TID1107-3039@10.100.14.163 1--RequestREGISTER
LT19-11-23-207613 --TID1061-3039@10.100.14.163 2--Response200
LT19-11-23-212050 --TID1062-3039@10.100.14.163 2--Response100
LT19-11-23-217322 --TID1084-3039@10.100.14.163 2--RequestREGISTER
LT19-11-23-222269 --TID906-3039@10.100.14.163 1--RequestREGISTER

were LT is logtime (hr.,min.,sec,usec) TID is transaction ID and 3rd and last is either REGISTER, 200, 100 or 401.
Now for first 10 sec.logtime . i.e. from LT 19-10-13-400922 to 19-10-23-234561
I want no. of occurrence of REGISTER, 200,100 and 401 and also no. of occurence of unique TID.

guys i need your help infact a temaplate code because i am not a perl guru.

I hope that you guys will help me out to fix this issue.

Thanks in advance.

ABHI

open(INI, "reg.txt") or die "cant open the file $!";
undef $/;
$file=<INI>;
close (INI);

while ($file =~ m/(.*?) --TID(.*?)@(\d+)\.(\d+)\.(\d+)\.(\d+)\s/gi)
{
    $Ti[$i++]="$2";
    $Re[$i++]="$4";
    $TR[$i++]="$2 : $4";
}

my @uniq1= grep !$serach1{$_}++, @TR;
my @uniq2= grep !$serach2{$_}++, @Ti;
my @uniq3= grep !$serach3{$_}++, @Re;

print "Register\n";
foreach (sort @uniq3){  print $_ ."\n";}print "\n\n";

print "TID : Register\n";
foreach (sort @uniq1){  print $_ ."\n";}print "\n\n";

print "TID\n";
foreach (sort @uniq2){  print $_ ."\n";}print "\n\n";
DATA
LT19-10-13-400922 --TID1-3039@10.105.14.163 1--RequestREGISTER
LT19-10-13-405432 --TID1-3039@10.100.14.163 1--Response100
LT19-10-13-410015 --TID1-3039@10.101.14.163 1--Response401
LT19-10-13-524129 --TID2-3039@10.101.14.163 1--Response100
LT19-10-13-528946 --TID2-3039@10.100.14.163 1--Response401
LT19-10-13-534280 --TID2-3039@10.108.14.163 2--RequestREGISTER
LT19-10-13-538468 --TID3-3039@10.100.14.163 1--Response100
LT19-10-13-543036 --TID3-3039@10.105.14.163 1--Response401
OUTPUT
Register

100
101
105
108


TID : Register

1-3039 : 100
1-3039 : 101
1-3039 : 105
2-3039 : 100
2-3039 : 101
2-3039 : 105
2-3039 : 108
3-3039 : 100
4-3039 : 100


TID

1-3039
2-3039
3-3039
4-3039

That's a rather messy way, I'd suggest a simpler route:

use strict;
use warnings;

open(my $INI, '<', "reg.txt") or die "cant open the file $!"; #always use three param open, and assign to a variable.

my %results;

while (<$INI>) { #more idiomatic
    #don't parenthasise (capture) what you don't need
    if (m/LT[-0-9]+? --TID(.*?)@\d+\.(\d+)(\.\d+){2}\s/i) {
        push @{$results{$1}}, $2; #assign to a Hash of Arrays
    }
}

foreach my $register (keys %results) {
    foreach my $tid (@{$results{$register}}) {
	print "$tid: $register \n";
    }
}

close $INI;

Thanks alot for your interest :)

In this code time is not considered i.e. i wanted the no. of occurrence (counts) of unique 401, register, 200, 100 messages for first 10 seconds.
Here i m defining the problem from scratch

we have have attached text file as reg.txt

LT19-10-13-400922 --TID1-3039 1--RequestREGISTER
LT19-10-13-405432 --TID1-3039 1--Response100
LT19-10-13-410015 --TID1-3039 1--Response401
LT19-10-13-415481 --TID1-3039 2--RequestREGISTER
LT19-10-13-419800 --TID1-3039 2--Response100
LT19-10-13-426400 --TID2-3039 1--RequestREGISTER
LT19-10-13-463320 --TID3-3039 1--RequestREGISTER
LT19-10-13-514112 --TID4-3039 1--RequestREGISTER
LT19-10-13-519524 --TID1-3039 2--Response200
LT19-10-13-524129 --TID2-3039 1--Response100
LT19-10-13-528946 --TID2-3039 1--Response401
LT19-10-13-534280 --TID2-3039 2--RequestREGISTER
LT19-10-13-538468 --TID3-3039 1--Response100
LT19-10-13-543036 --TID3-3039 1--Response401
LT19-10-13-548314 --TID3-3039 2--RequestREGISTER
LT19-10-13-552941 --TID4-3039 1--Response100
LT19-10-13-557932 --TID4-3039 1--Response401
LT19-10-13-563320 --TID4-3039 2--RequestREGISTER
LT19-10-13-567495 --TID2-3039 2--Response100
LT19-10-13-572397 --TID5-3039 1--RequestREGISTER
LT19-10-13-583242 --TID6-3039 1--RequestREGISTER
LT19-10-13-588624 --TID2-3039 2--Response200
LT19-10-13-593035 --TID3-3039 2--Response100
LT19-10-13-597783 --TID7-3039 1--RequestREGISTER
LT19-10-13-630047 --TID8-3039 1--RequestREGISTER
LT19-10-13-656120 --TID3-3039 2--Response200
LT19-10-13-660408 --TID4-3039 2--Response100
LT19-10-13-665185 --TID9-3039 1--RequestREGISTER
LT19-10-13-695558 --TID10-3039 1--RequestREGISTER
LT19-10-13-745194 --TID4-3039 2--Response200
LT19-10-13-749464 --TID5-3039 1--Response100
LT19-10-13-754091 --TID5-3039 1--Response401
LT19-10-13-759572 --TID5-3039 2--RequestREGISTER
LT19-10-13-764180 --TID6-3039 1--Response100
LT19-10-13-769033 --TID6-3039 1--Response401
LT19-10-13-774300 --TID6-3039 2--RequestREGISTER
LT19-10-13-779059 --TID11-3039 1--RequestREGISTER
LT19-10-13-783341 --TID7-3039 1--Response100
LT19-10-13-788233 --TID7-3039 1--Response401
LT19-10-13-793818 --TID7-3039 2--RequestREGISTER
LT19-10-13-798178 --TID8-3039 1--Response100
LT19-10-13-804730 --TID8-3039 1--Response401
LT19-10-13-810105 --TID8-3039 2--RequestREGISTER
LT19-10-13-814360 --TID9-3039 1--Response100
LT19-10-13-819234 --TID9-3039 1--Response401
LT19-10-13-824808 --TID9-3039 2--RequestREGISTER
LT19-10-13-829216 --TID10-3039 1--Response100
LT19-10-13-833872 --TID10-3039 1--Response401
LT19-10-13-839076 --TID10-3039 2--RequestREGISTER
LT19-10-13-843331 --TID5-3039 2--Response100
LT19-10-13-848486 --TID12-3039 1--RequestREGISTER
LT19-10-13-855283 --TID13-3039 1--RequestREGISTER
LT19-10-13-860688 --TID5-3039 2--Response200
LT19-10-13-865292 --TID6-3039 2--Response100
LT19-10-13-870197 --TID14-3039 1--RequestREGISTER
LT19-10-13-875289 --TID6-3039 2--Response200
LT19-10-13-879694 --TID11-3039 1--Response100
LT19-10-13-884722 --TID11-3039 1--Response401
LT19-10-13-890117 --TID11-3039 2--RequestREGISTER
LT19-10-13-895017 --TID15-3039 1--RequestREGISTER
LT19-10-13-899176 --TID7-3039 2--Response100
LT19-10-13-905375 --TID16-3039 1--RequestREGISTER
LT19-10-13-911060 --TID7-3039 2--Response200
LT19-10-13-915691 --TID8-3039 2--Response100
LT19-10-13-929259 --TID17-3039 1--RequestREGISTER
LT19-10-13-956695 --TID8-3039 2--Response200
LT19-10-13-963782 --TID9-3039 2--Response100
LT19-10-13-968929 --TID18-3039 1--RequestREGISTER
LT19-10-13-996787 --TID19-3039 1--RequestREGISTER
LT19-10-14-2450 --TID9-3039 2--Response200
LT19-10-14-6953 --TID10-3039 2--Response100
LT19-10-14-44163 --TID20-3039 1--RequestREGISTER
LT19-10-14-49758 --TID10-3039 2--Response200
LT19-10-14-58376 --TID12-3039 1--Response100
LT19-10-14-64918 --TID12-3039 1--Response401
LT19-10-14-73129 --TID12-3039 2--RequestREGISTER
LT19-10-14-77624 --TID13-3039 1--Response100
LT19-10-14-82416 --TID13-3039 1--Response401
LT19-10-14-97404 --TID13-3039 2--RequestREGISTER
LT19-10-14-102111 --TID14-3039 1--Response100
LT19-10-14-107264 --TID14-3039 1--Response401
LT19-10-14-112883 --TID14-3039 2--RequestREGISTER
LT19-10-14-126918 --TID11-3039 2--Response100
LT19-10-14-131970 --TID21-3039 1--RequestREGISTER
LT19-10-14-136874 --TID22-3039 1--RequestREGISTER
LT19-10-14-141935 --TID11-3039 2--Response200
LT19-10-14-151963 --TID15-3039 1--Response100
LT19-10-14-159891 --TID15-3039 1--Response401
LT19-10-14-165773 --TID15-3039 2--RequestREGISTER
LT19-10-14-170191 --TID16-3039 1--Response100
LT19-10-14-179048 --TID16-3039 1--Response401
LT19-10-14-189169 --TID16-3039 2--RequestREGISTER
LT19-10-14-193700 --TID17-3039 1--Response100
LT19-10-14-198481 --TID17-3039 1--Response401
LT19-10-14-203712 --TID17-3039 2--RequestREGISTER
LT19-10-14-217674 --TID18-3039 1--Response100
LT19-10-14-222618 --TID18-3039 1--Response401
LT19-10-14-227888 --TID18-3039 2--RequestREGISTER
LT19-10-14-232135 --TID19-3039 1--Response100
LT19-10-14-242840 --TID19-3039 1--Response401
LT19-10-14-251244 --TID19-3039 2--RequestREGISTER
LT19-10-14-255903 --TID20-3039 1--Response100
LT19-10-14-261026 --TID20-3039 1--Response401
LT19-10-14-272726 --TID20-3039 2--RequestREGISTER
LT19-10-14-280103 --TID12-3039 2--Response100
LT19-10-14-285046 --TID23-3039 1--RequestREGISTER
LT19-10-14-289948 --TID24-3039 1--RequestREGISTER
LT19-10-14-299128 --TID12-3039 2--Response200
LT19-10-14-307900 --TID13-3039 2--Response100
LT19-10-14-313453 --TID25-3039 1--RequestREGISTER
LT19-10-14-318659 --TID13-3039 2--Response200
LT19-10-14-322962 --TID14-3039 2--Response100
LT19-10-14-337087 --TID26-3039 1--RequestREGISTER
LT19-10-14-342329 --TID14-3039 2--Response200
LT19-10-14-346616 --TID21-3039 1--Response100
LT19-10-14-351511 --TID21-3039 1--Response401
LT19-10-14-365907 --TID27-3039 1--RequestREGISTER
LT19-10-14-371249 --TID21-3039 2--RequestREGISTER
LT19-10-14-375567 --TID22-3039 1--Response100
LT19-10-14-380353 --TID22-3039 1--Response401
LT19-10-14-394616 --TID22-3039 2--RequestREGISTER
LT19-10-14-399345 --TID15-3039 2--Response100
LT19-10-14-404781 --TID28-3039 1--RequestREGISTER
LT19-10-14-409921 --TID15-3039 2--Response200
LT19-10-14-416252 --TID16-3039 2--Response100
LT19-10-14-428400 --TID29-3039 1--RequestREGISTER
LT19-10-14-433921 --TID16-3039 2--Response200
LT19-10-14-439302 --TID30-3039 1--RequestREGISTER
LT19-10-14-450187 --TID17-3039 2--Response100
LT19-10-14-455489 --TID31-3039 1--RequestREGISTER
LT19-10-14-460929 --TID17-3039 2--Response200
LT19-10-14-465590 --TID18-3039 2--Response100
LT19-10-14-470875 --TID32-3039 1--RequestREGISTER
LT19-10-14-476327 --TID18-3039 2--Response200
LT19-10-14-480828 --TID19-3039 2--Response100
LT19-10-14-491642 --TID33-3039 1--RequestREGISTER
LT19-10-14-496883 --TID19-3039 2--Response200
LT19-10-14-501668 --TID34-3039 1--RequestREGISTER
LT19-10-14-506044 --TID20-3039 2--Response100
LT19-10-14-527348 --TID35-3039 1--RequestREGISTER
LT19-10-14-561698 --TID20-3039 2--Response200
LT19-10-14-566229 --TID23-3039 1--Response100
LT19-10-14-571124 --TID23-3039 1--Response401
LT19-10-14-576440 --TID23-3039 2--RequestREGISTER
LT19-10-14-580593 --TID24-3039 1--Response100
LT19-10-14-585272 --TID24-3039 1--Response401
LT19-10-14-590429 --TID24-3039 2--RequestREGISTER
LT19-10-14-594693 --TID25-3039 1--Response100
LT19-10-14-605456 --TID25-3039 1--Response401
LT19-10-14-610757 --TID25-3039 2--RequestREGISTER
LT19-10-14-614948 --TID26-3039 1--Response100
LT19-10-14-619566 --TID26-3039 1--Response401
LT19-10-14-624810 --TID26-3039 2--RequestREGISTER
LT19-10-14-629287 --TID27-3039 1--Response100
LT19-10-14-634223 --TID27-3039 1--Response401
LT19-10-14-639448 --TID27-3039 2--RequestREGISTER
LT19-10-14-644465 --TID36-3039 1--RequestREGISTER
LT19-10-14-650249 --TID21-3039 2--Response100
LT19-10-14-655826 --TID37-3039 1--RequestREGISTER
LT19-10-14-661506 --TID21-3039 2--Response200
LT19-10-14-666247 --TID22-3039 2--Response100
LT19-10-14-671712 --TID38-3039 1--RequestREGISTER
LT19-10-14-677446 --TID22-3039 2--Response200
LT19-10-14-682278 --TID28-3039 1--Response100
LT19-10-14-687565 --TID28-3039 1--Response401
LT19-10-14-693113 --TID28-3039 2--RequestREGISTER
LT19-10-14-697612 --TID29-3039 1--Response100
LT19-10-14-702523 --TID29-3039 1--Response401
LT19-10-14-707929 --TID29-3039 2--RequestREGISTER
LT19-10-14-713059 --TID39-3039 1--RequestREGISTER
LT19-10-14-717353 --TID30-3039 1--Response100
LT19-10-14-721990 --TID30-3039 1--Response401
LT19-10-14-727263 --TID30-3039 2--RequestREGISTER
LT19-10-14-731725 --TID31-3039 1--Response100
LT19-10-14-738120 --TID31-3039 1--Response401
LT19-10-14-743610 --TID31-3039 2--RequestREGISTER
LT19-10-14-747832 --TID32-3039 1--Response100
LT19-10-14-752486 --TID32-3039 1--Response401
LT19-10-14-757810 --TID32-3039 2--RequestREGISTER
LT19-10-14-762315 --TID33-3039 1--Response100
LT19-10-14-767219 --TID33-3039 1--Response401
LT19-10-14-772458 --TID33-3039 2--RequestREGISTER
LT19-10-14-776622 --TID34-3039 1--Response100
LT19-10-14-781291 --TID34-3039 1--Response401
LT19-10-14-786576 --TID34-3039 2--RequestREGISTER
LT19-10-14-791085 --TID35-3039 1--Response100
LT19-10-14-796017 --TID35-3039 1--Response401
LT19-10-14-801373 --TID35-3039 2--RequestREGISTER
LT19-10-14-805592 --TID23-3039 2--Response100
LT19-10-14-810374 --TID40-3039 1--RequestREGISTER
LT19-10-14-815272 --TID41-3039 1--RequestREGISTER
LT19-10-14-820514 --TID23-3039 2--Response200
LT19-10-14-824913 --TID24-3039 2--Response100
LT19-10-14-829772 --TID42-3039 1--RequestREGISTER
LT19-10-14-834593 --TID43-3039 1--RequestREGISTER
LT19-10-14-839384 --TID44-3039 1--RequestREGISTER
LT19-10-14-860083 --TID45-3039 1--RequestREGISTER
LT19-10-14-868697 --TID24-3039 2--Response200
LT19-10-14-873043 --TID25-3039 2--Response100
LT19-10-14-897411 --TID46-3039 1--RequestREGISTER
LT19-10-14-921380 --TID25-3039 2--Response200
LT19-10-14-926613 --TID26-3039 2--Response100
LT19-10-14-931467 --TID47-3039 1--RequestREGISTER
LT19-10-14-963221 --TID48-3039 1--RequestREGISTER
LT19-10-14-985076 --TID26-3039 2--Response200
LT19-10-14-989462 --TID27-3039 2--Response100
LT19-10-14-994391 --TID49-3039 1--RequestREGISTER
LT19-10-15-29326 --TID50-3039 1--RequestREGISTER
LT19-10-15-35217 --TID27-3039 2--Response200
........................................
.......................................

now for first 10 second i.e. from 19-10-13-xyzw to 19-10-23-zxcs
we want No. 1-> no. of count of REGISTER unique TID (that is 1-3039 1,2-3039 1, .......), keep in mind 1-3039 1 and 1-3039 2 are same.whereas 1-3039 1 and 2-3039 1 are different. This differ only in case of 401 response and 200 response.
No. 2-> No. of count of 401 responses whose(REGISTER and 401) TIDs are same
i.e.
LT19-10-13-400922 --TID1-3039 1--RequestREGISTER
LT19-10-13-410015 --TID1-3039 1--Response401
No. 3->
No. of count of 200 responses whose (REGISTER and 200) TIDs are same.
confuse???????????????????????????
lets take simple example
Time TID Message
13 11 REGISTER
14 11 401
14 12 REGISTER
15 21 REGISTER
15 12 200
16 31 REGISTER
16 21 401
17 31 401
18 22 REGISTER
19 32 REGISTER
20 22 200
21 32 200
22 01 401
23 01 200

so the answer should be
for fist 10 seconds
1. count of unique REGISTER are 3
2. count of 401 whose TIDs are same as REGISTER are 3
3. count of 200 whose TIDs are same as REGISTER are 3

thanks in advance..................waiting for early reply friends

.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.