Sponsored Content
Top Forums Shell Programming and Scripting Using perl to obtain stats instead of grep Post 302415108 by durden_tyler on Wednesday 21st of April 2010 07:16:35 PM
Old 04-21-2010
If you want a quick and dirty one-liner (not in the literal sense though), you could do something like this -

Code:
$ 
$ 
$ cat -n f3
     1    2010-04-20_00:01:02:307,SUBS_BOOK_ACC,system@bkpass_1271_718059_59480,441234567899,EPASS088,,success,9999
     2    2010-04-20_00:01:18:139,SUBS_BOOK_ACC,system@bkpass_1271_718076_442346,441234567899,EPASS088,,success,6585
     3    2010-04-20_00:01:24:335,SUBS_BOOK_ACC,system@bkpass_1271_718080_786699,441234567899,EPASSV09,,PAY payment failed,211
     4    2010-04-20_00:01:24:335,SUBS_BOOK_ACC,system@bkpass_1271_718080_786699,441234567899,EPASSV09,,PAY payment failed,222
     5    2010-04-20_00:01:24:335,SUBS_BOOK_ACC,system@bkpass_1271_718080_786699,441234567899,EPASSV09,,success,8888
     6    2010-04-20_00:01:18:139,SUBS_BOOK_ACC,system@bkpass_1271_718076_442346,441234567899,EPASS088,,PAY payment failed,2345
     7    2010-04-20_00:01:18:139,SUBS_BOOK_ACC,system@bkpass_1271_718076_442346,441234567899,EPASS013,,success,6585
$ 
$ ##
$ perl -F, -ane 'if ($F[6] eq "success"){$s{$F[4]}++} elsif ($F[6] =~ m/failed/){$f{$F[4]}++}; $x{$F[4]}=1;
                 END {
                   printf("%10s %10s %10s\n","Pass ID","Successes","Failures");
                   foreach $i (keys %x) {printf("%10s %10s %10s\n", $i, $s{$i} // 0, $f{$i} // 0)}
                 }' f3
   Pass ID  Successes   Failures
  EPASS013          1          0
  EPASSV09          1          2
  EPASS088          2          1
$ 
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Newbie to perl - Help with stats script

Hi, this is my first post so here goes..... I need help... I am trying to write a script to produce some stats based on a number of searches in a log file. Now i know how to do this using multiple variables which are really just greps, but I want a more efficent way of doing this as my poor... (1 Reply)
Discussion started by: ARwebble
1 Replies

2. Shell Programming and Scripting

grep using Perl

I'm using perl to do a grep of each line in a vendor file and find its occurrences in a specific directory. Any values found is saved in @dir. .....(file opened, etc.) .... while ($line=<FILE>){ @dir = `grep $line * `; } It's the specific usage of the system grep that I'm having... (7 Replies)
Discussion started by: gavineq
7 Replies

3. Shell Programming and Scripting

Perl grep

OK here's the situation: I have got these lines which I have got to parse. If the line contains a particular string and any element from a previously defined array I need to take that particular line and do some further processing. if ((grep(/$_/,$1)) && (grep($pattern,@myarr))) { #Do... (2 Replies)
Discussion started by: King Nothing
2 Replies

4. Shell Programming and Scripting

How to execute Grep in Perl.

$ grep edge test_1 |sort|uniq >result.txt $more result.txt edge-a-pas01.com 10.12.10.11 edge-b-pas02.com 10.12.10.12 edge-c-pas03.com 10.12.10.50 edge-d-pas03.com 10.12.10.10 how do we execute the above grep command using perl? Thanks in advance. (3 Replies)
Discussion started by: sureshcisco
3 Replies

5. Shell Programming and Scripting

grep in perl

Hello I want to grep a line from a file saved in some directory. Can anyone please correct the code below: #!/usr/bin/perl -w $file = "/home/output.txt" $grep_line = "closing zip for topic"; `grep $grep_line* $file`; (1 Reply)
Discussion started by: sureshcisco
1 Replies

6. Shell Programming and Scripting

Perl + and Grep

Hi All i have this script that uses glob to look in /var/log/messages.* my @messagefiles = glob "/var/log/messages.*"; and the code that uses it is this grep { /NVRM: Xid/ } @messages) but this spits out this /var/log/messages-20111030:Oct 25 13:43:04 brent kernel: NVRM:... (10 Replies)
Discussion started by: ab52
10 Replies

7. Shell Programming and Scripting

GREP Issue in Perl

Im storing multiple functions in a varaible called $check... The variable check contains the following: a() b() c() ... ..etc now im checking individually which function is kept in which file using GREP if ( grep \$check \i, <FILE> ) The problem is im getting the output for the... (1 Reply)
Discussion started by: rajkrishna89
1 Replies

8. Shell Programming and Scripting

Grep in PERL

Hi, Can anybody let me know how this grep will work. The input and output is not known. Also can you give me the details of any link where i can find clearly about grep Thanks in advance (1 Reply)
Discussion started by: irudayaraj
1 Replies

9. Shell Programming and Scripting

How to grep a pattern in perl?

hello Everyone i am a newbie. i have a file which contains the following E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\winclockmtq.lib E:\gtmproj\script\i486_nt\obj\check_geomtools.exe:... (12 Replies)
Discussion started by: Rashid Khan
12 Replies

10. Shell Programming and Scripting

Need help in solving to obtain desired print output using awk or perl or any commands, Please help!!

I have an file which have data in lines as follows ad, findline=24,an=54,ab=34,av=64,ab=7989,ab65=34,aj=323,ay=34,au=545,ad=5545 ab,abc,an10=23,an2=24,an31=32,findline=00,an33=23,an32=26,an40=45,ac23=5,ac=87,al=76,ad=26... (3 Replies)
Discussion started by: deepKrish
3 Replies
CMUTEX(3)						     Common Library Functions							 CMUTEX(3)

NAME
Cmutex - LCG Mutex inferface SYNOPSIS
#include <Cmutex.h> void Cmutex_init(int (*lockroutine)(void *addr, int timeout), int (*unlockroutine)(void * addr)); int Cmutex_lock(void *addr, int timeout); int Cmutex_unlock(void *addr); DESCRIPTION
Cmutex is a common API interface for application compiled or not with the multithread flag. If the application do never initialize the Cmu- tex package, using Cmutex_init, and two arguments that are the addresses of the mutex lock and unlock functions, lockfunction and unlock- function respectively, then all Cmutex calls are dummy operations. Otherwise any call to Cmutex_lock will raise a call to lockfunction , and any call to Cmutex_unlock will raise a call to unlockfunction. Please note that the Cmutex package is initially meant to be interfaced with Cthread only. Cmutex_lock takes as argument the address addr of anything that is static in your userspace, such as a 'static int variable;' address (see EXAMPLE section below), and a timeout expressed in second unit. If timeout is lower than zero, the operation will block until the mutex is granted. If it is zero, the operation will try to have the mutex and immediately return, possibly with failure. If it is greater than zero, operation will exit if the timeout is reached. Please refer to Cthread_mutex_timedlock description in the Cthread man page. Return code of Cmutex_lock is 0 if success, -1 on failure. If failure the serrno error code is set appropriately. Cmutex_unlock releases a lock that you previously gained using Cmutex_lock and the same address value addr. Return code is 0 if success and -1 on failure, error code is then in the serrno variable. ERRORS
If the Cthread interface is chosen and activated, the errors value are in the serrno variable: SECTHREADINIT LCG Thread interface initialization error A thread initialisation call failed. In principle, on UNIX this will be a call to pthread_mutex_init (and possibly pthread_mutex- attr_init) that failed, on Windows/NT this might be a call to CreateMutex. SECTHREADERR LCG Thread interface failure in calling your thread library A thread call to your native system library (like the pthread one on UNIX) failed. Please note that this is differentiated to the Cthread initialization and can happen if you are using too much thread keys, for example. This is really a run-time error only con- cerning your operating system thread interface. Any other system call failure, but not a thread one, and not at the initialisation step, will set serrno to SEINTERNAL SEOPNOTSUP Operation not supported This can be generated only if you compiled Cthread with a -DCTHREAD_PROTO flag that Cthread do not know about. Check your LCG con- figuration site.def. SEINTERNAL Internal error You can have more information by compiling the Cthread package with the flag -DCTHREAD_DEBUG, and catching the printout on your stderr stream. This is any system call that failed (like malloc()), except those to the thread library (for which SECTHREADERR or SECTHREADINIT is to be found), or any critical internal run-time error (such as a non correct value found in some Cthread internal structures). SETIMEDOUT (routines with a timeout parameter only) Timed out You called a routine with a timeout value greater than zero that reached the maximum number of timeout seconds in waiting state. EINVAL Invalid parameters You called a routine with invalid parameter(s). Please check your code. EDEADLK Deadlock Mutex is already locked by the calling thread (PTHREAD_MUTEX_ERRORCHECK mutexes only, this is not the default and should not happen via Cmutex) EBUSY Device or resource busy Mutex is already locked by another thread. EPERM Permission denied Mutex is now owned by the calling thread (PTHREAD_MUTEX_ERRORCHECK mutexes only, this is not the default and should not happen via Cmutex) EXAMPLE
/* * Here follows an example. The call to Cthread_init routine shows * that multi-threaded mode is explicitly activated by the application * (you will then have to link with the thread library). Neverthless, * you can very well call some other external library, and leave as it is * the Cmutex calls. */ #include <Cmutex.h> #include <Cthread_api.h> #include <serrno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <log.h> int this; extern int Cthread_debug; int main() { Cthread_init(); /* Comment this and Cmutex calls will become dummy */ initlog("testit",LOG_INFO,""); if (Cmutex_lock(&this,10) != 0) { fprintf(stderr,"### Cmutex_lock (%s) ",sstrerror(serrno)); } if (Cmutex_unlock(&this) != 0) { fprintf(stderr,"### Cmutex_unlock (%s) ",sstrerror(serrno)); } } SEE ALSO
Cthread, serrno AUTHOR
LCG Grid Deployment Team LCG
$Date: 2010-04-05 09:51:26 +0200 (Mon, 05 Apr 2010) $ CMUTEX(3)
All times are GMT -4. The time now is 07:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy