Sponsored Content
Top Forums Shell Programming and Scripting Using perl to obtain stats instead of grep Post 302415406 by turk451 on Thursday 22nd of April 2010 01:22:08 PM
Old 04-22-2010
Hi Jeffers,

I made the changes that you had listed, and it worked fine for me:

Code:
#!/usr/bin/perl -w
use POSIX;

open (LOGFILE, $ARGV[0]) or die ("Could not open log file.");

foreach $line (<LOGFILE>){
        chomp($line);
        if (length($line) > 0) {
                @lineArray=split(",",$line);
                if ( $lineArray[1] =~ /SUBS_BOOK_ACC/ ) {
                        $key = $lineArray[4];
                        if (! defined $resultsHash{ $key }) {
                                $resultsHash{ $key } = [0,0,0];
                        }
                        $temp = $resultsHash{ $key };
                        if ( $lineArray[6] =~ /success/ ) {
                                @$temp[0]++;
                        } elsif ( $lineArray[6] =~ /failed/ ) {
                                @$temp[1]++;
                        } elsif ( $lineArray[6] =~ /subscription already booked/ ) {
                                @$temp[2]++;
                        }
                        $resultsHash{ $key } = $temp;
                }
        }
}

foreach (sort keys %resultsHash) {
    $temp = $resultsHash{$_};
    print "$_ : @$temp\n";
}

sample data and output:

Code:
eturk-linux 10:20:31 (~)> cat data.dat
2010-04-20_00:01:02:307,SUBS_BOOK_ACC,system@bkpass_1271_718059_59480,441234567899,EPASS088,,success,9999
2010-04-20_00:01:18:139,SUBS_BOOK_ACC,system@bkpass_1271_718076_442346,441234567899,EPASS088,,success,6585
2010-04-20_00:01:24:335,SUBS_BOOK_ACC,system@bkpass_1271_718080_786699,441234567899,EPASSV09,,PAY payment failed,211
2010-04-20_00:01:24:335,SUBS_BOOK_ACC,system@bkpass_1271_718080_786699,441234567899,EPASSV09,,PAY payment failed,222
2010-04-20_00:01:24:335,SUBS_BOOK_ACC,system@bkpass_1271_718080_786699,441234567899,EPASSV09,,success,8888
2010-04-20_00:01:18:139,SUBS_BOOK_ACC,system@bkpass_1271_718076_442346,441234567899,EPASS088,,PAY payment failed,2345
2010-04-20_00:01:18:139,SUBS_BOOK_ACC,system@bkpass_1271_718076_442346,441234567899,EPASS013,,success,6585
2010-04-20_00:01:18:139,SUBS_BOOK_ACC,system@bkpass_1271_718076_442346,441234567899,EPASS013,,subscription already booked,6585
2010-04-20_00:01:18:139,SUBS_BOOK_ACC,system@bkpass_1271_718076_442346,441234567899,EPASS013,,subscription already booked,6585
2010-04-20_00:01:18:139,SUBS_BOOK_ACC,system@bkpass_1271_718076_442346,441234567899,EPASS013,,subscription already booked,6585
2010-04-20_00:01:18:139,SUBS_BOOK_ACC,system@bkpass_1271_718076_442346,441234567899,EPASS013,,subscription already booked,6585
eturk-linux 10:20:52 (~)> ./filter.pl data.dat
EPASS013 : 1 0 4
EPASS088 : 2 1 0
EPASSV09 : 1 2 0
eturk-linux 10:20:58 (~)>

 

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
TOTAL(1)						      General Commands Manual							  TOTAL(1)

NAME
total - sum up columns SYNOPSIS
total [ -m ][ -sE | -p | -u | -l ][ -i{f|d}[N] ][ -o{f|d} ][ -tC ][ -N [ -r ]] [ file .. ] DESCRIPTION
Total sums up columns of real numbers from one or more files and prints out the result on its standard output. By default, total computes the straigt sum of each input column, but multiplication can be specified instead with the -p option. Likewise, the -u option means find the upper limit (maximum), and -l means find the lower limit (minimum). Sums of powers can be computed by giving an exponent with the -s option. (Note that there is no space between the -s and the exponent.) This exponent can be any real number, positive or negative. The absolute value of the input is always taken before the power is computed in order to avoid complex results. Thus, -s1 will produce a sum of absolute values. The default power (zero) is interpreted as a straight sum without taking absolute values. The -m option can be used to compute the mean rather than the total. For sums, the arithmetic mean is computed. For products, the geomet- ric mean is computed. (A logarithmic sum of absolute values is used to avoid overflow, and zero values are silently ignored.) If the input data is binary, the -id or -if option may be given for 64-bit double or 32-bit float values, respectively. Either option may be followed immediately by an optional count, which defaults to 1, indicating the number of double or float binary values to read per record on the input file. (There can be no space between the option and this count.) Similarly, the -od and -of options specify binary double or float output, respectively. These options do not need a count, as this will be determined by the number of input channels. A count can be given as the number of lines to read before computing a result. Normally, total reads each file to its end before producing its result, but this behavior may be overridden by inserting blank lines in the input. For each blank input line, total produces a result as if the end-of-file had been reached. If two blank lines immediately follow each other, total closes the file and proceeds to the next one (after reporting the result). The -N option (where N is a decimal integer) tells total to produce a result and reset the calculation after every N input lines. In addition, the -r option can be specified to override reinitialization and thus give a running total every N lines (or every blank line). If the end of file is reached, the current total is printed and the calculation is reset before the next file (with or without the -r option). The -tC option can be used to specify the input and output tab character. The default tab character is TAB. If no files are given, the standard input is read. EXAMPLE
To compute the RMS value of colon-separated columns in a file: total -t: -m -s2 input To produce a running product of values from a file: total -p -1 -r input BUGS
If the input files have varying numbers of columns, mean values will certainly be off. Total will ignore missing column entries if the tab separator is a non-white character, but cannot tell where a missing column should have been if the tab character is white. AUTHOR
Greg Ward SEE ALSO
cnt(1), neaten(1), rcalc(1), rlam(1), tabfunc(1) RADIANCE
2/3/95 TOTAL(1)
All times are GMT -4. The time now is 02:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy