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
ARBTT-STATS(1)							Program references						    ARBTT-STATS(1)

NAME
arbtt-stats - generate statistics from the arbtt data samples SYNOPSIS
arbtt-stats [OPTION...] DESCRIPTION
arbtt-stats reads the samples that were recorded so far by arbtt-capture from the log file, filters them according to the users specifications and generates one or more reports from the data. When run without any options, --total-time is assumed. The order in which filters (--exclude, --only, --also-inactive and --filter) and reports are passed to the program is irrelevant: All filters given on the command line are active for all reports. OPTIONS
-h, -?, --help shows a short summary of the available options, and exists. -V, --version shows the version number, and exists. --logfile FILE logfile to use instead of ~/.arbtt/capture.log --categorizefile categorize file to use instead of ~/.arbtt/categorize.cfg Filtering options -x TAG, --exclude TAG Ignore any data samples that have been assigned this tag or category. To distinguish tags and categories, the latter have to be entered followed by a colon. Can be given more than once. -o TAG, --only TAB Ignore any data samples that have not been assigned this tag. To distinguish tags and categories, the latter have to be entered followed by a colon. Can be given more than once. --also-inactive by default, arbtt-stats ignores any samples which have been assigned the tag inactive. This flag disables this behaviour. -f CONDITION, --filter CONDITION Only consider samples matching the given condition, which follows the same syntax as in categorize.cfg (Nonterminal Cond in the formal grammar specification found in the user guide). Report options -m PERCENTAGE, --min-percentage PERCENTAGE Ignore tags whose percentage is less than the value specified here. Default percentage: 1%. --output-exclude TAG Skip this tag or category when printing statistics. Only affects the reports --total-time and --category. To distinguish tags and categories, the latter have to be entered followed by a colon. Can be given more than once. --output-only TAG Prints statistics only for the specified tag or category. Only affects the reports --total-time and --category. To distinguish tags and categories, the latter have to be entered followed by a colon. Can be given more than once. --output-format FORMAT Specify the report output format, may be one of: text, csv (comma-separated values), tsv (TAB-separated values). Default format: text. Reports -i, --information Various bits of information about the recorded data, such as total time recorded, number of records etc. In this report, "time recorded" is the sum of all samples, including inactive and those that are disabled by the filter, while "time selected" is the sum of the samples that are matched by the given filters. -t, --total-time For all tags, print the part of the selected time with this tag applied to, both as an absolute value and a percentage of the selected time. -c CATEGORY, --category CATEGORY For the given category, give the textual equivalent of a pie chart: For each possible value of the category, including one for "no tag of this category present", give the absolute time and fraction. Entries which are not displayed because of the option --min-percentage are aggregated. --each-category This is just a shortcut for a series of --category options, one for each category found in the data. --intervals [TAG|CATEGORY:] This report lists all periods of consecutive time intervals where the given tag has been applied to, or where the given category has the same value. To distinguish tags and categories, the latter have to be entered followed by a colon. This report will give wrong results if an activity has been carried out at the end of a session and right at the beginning, as the intermediate time is thought to be part of the interval. Inactive times while arbtt-capture is running will separate the results as expected. EXAMPLES
Some useful examples of what you can do with arbtt-stats are provided here: # Only consider the time when I was programming in Haskell arbtt-stats -o Editing-Haskell # Tell me what evolution folders I spend my time in when I actually do # work with e-Mail arbtt-stats -o Program:evolution -c Evo-Folder # Generate statistics about the last hour arbtt-stats -f '$sampleage < 1:00' FILES
~/.arbtt/capture.log binary file, storing the arbtt data samples ~/.arbtt/categorize.cfg specification of the arbtt categorizer syntax. A detailed description is given in the section called "Configuring the arbtt categorizer (arbtt-stats)" SEE ALSO
See the arbtt manual for more information and the arbtt hackage page[1] for newer versions of arbtt. AUTHORS
Joachim Breitner <mail@joachim-breitner.de> Main author of arbtt Sergey Astanin <s.astanin@gmail.com> Contributor Martin Kiefel <mk@nopw.de> Contributor Muharem Hrnjadovic <muharem@linux.com> Contributor NOTES
1. arbtt hackage page http://www.hackage.org/package/arbtt arbtt manual 04/07/2012 ARBTT-STATS(1)
All times are GMT -4. The time now is 01:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy