![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| Calling a perl script from a perl script | new2ss | Shell Programming and Scripting | 6 | 05-24-2009 05:03 PM |
| Include PERL script with in the unix shell script | ganapati | UNIX for Dummies Questions & Answers | 1 | 04-29-2008 12:18 PM |
| here document to automate perl script that call script | hogger84 | Shell Programming and Scripting | 3 | 10-22-2007 10:15 AM |
| Modify Perl script to work with txt - Permissions script | joangopan | Shell Programming and Scripting | 1 | 09-12-2007 11:38 PM |
| Perl: Run perl script in the current process | vino | Shell Programming and Scripting | 10 | 12-09-2005 10:45 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
help on perl script..
Hi perl gurus,
The below lines are the 1st few lines of my logfile to scan. Based on this, i need to get the TOP5 UserIDs having the most activities/transactions, and the top5 tasks as well. For example, thomsonj (appearing 4x sofar) would be the top1 UserID, and WithdrawCash (4x) would be the top1 Task. ..... ..... 04:45:48 >> ==========START of MESSAGE========== 04:45:48 >> UserID: gibsonwe 04:45:48 >> Task: CheckBalance 04:45:48 >> Processing.... 04:45:50 >> Response: Current balance is [$1] 07:30:27 >> ==========START of MESSAGE========== 07:30:27 >> UserID: thomsonj 07:30:27 >> Task: WithdrawCash 07:30:27 >> Processing.... 07:30:27 >> Response: [$1] dispensed 10:18:09 >> ==========START of MESSAGE========== 10:18:09 >> UserID: greendav 10:18:09 >> Task: FundTransfer 10:18:10 >> Response: Successfully transferred [$1] 13:47:23 >> ==========START of MESSAGE========== 13:47:23 >> UserID: thomsonj 13:47:23 >> Task: WithdrawCash 13:47:23 >> Processing.... 13:47:26 >> Response: [$1] dispensed 15:06:15 >> ==========START of MESSAGE========== 15:06:15 >> UserID: thomsonj 15:06:15 >> Task: CheckBalance 15:06:15 >> Processing.... 15:06:15 >> Response: Current balance is [$1] 17:44:50 >> ==========START of MESSAGE========== 17:44:50 >> UserID: greendav 17:44:50 >> Task: BillPayment 17:44:50 >> Processing.... 17:44:50 >> Response: Successfully paid [$1] 20:25:29 >> ==========START of MESSAGE========== 20:25:29 >> UserID: thomsonj 20:25:29 >> Task: WithdrawCash 20:25:29 >> Processing.... 20:25:29 >> Response: [$1] dispensed ..... ..... Any help would be greatly appreciated. Thanks much. |
|
||||
|
what u can do is use hash in perl
1. open file in read mode 2. use regex to get filed after "User Id:" 3. put this "user Id" as key in Hash if not present 4. every time you find user present increase key value by 1 5. at the end sort keys of hash and do print. following link might help Perl Hash Howto |
|
||||
|
Code:
sed 's/.*>>//' a > a.new
awk 'BEGIN{
FS=":"
un=0
tn=0}
{
if (index($1,"UserID")!=0)
user[$2]++
if (index($1,"Task")!=0)
task[$2]++
}
END{
for (i in user)
if(user[i]>un){un=user[i];u=i}
for(j in task)
if(task[j]>tn){tn=task[j];t=j}
print u" - "un
print t" - "tn
}' a.new
rm a.new
|
![]() |
| Bookmarks |
| Tags |
| perl, perl regex, regex |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|