The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
search ")" with egrep - egrep: syntax error sagarjani UNIX for Dummies Questions & Answers 7 10-14-2008 08:30 AM
egrep/grep result of more files tvrman Shell Programming and Scripting 3 08-07-2008 09:29 AM
Egrep cheat sheet anywhere? Looking for meaning of egrep -c leelm UNIX for Dummies Questions & Answers 2 01-11-2008 03:37 PM
perl - copying files BG_JrAdmin Shell Programming and Scripting 1 12-13-2007 09:50 PM
Perl Uploading Files sstevens UNIX for Advanced & Expert Users 16 02-24-2004 03:03 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-17-2008
thepurple thepurple is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 134
Its working. great.

Could you please help me to get the script how do it calculate like below from the outputfile-

How many CREATE with RESP:3*
How many CREATE with RESP:9*
How many CREATE with RESP:9??3?????
How many CREATE with RESP:9??3???96


CREATE
RESP:3010


CREATE
RESP:911364896

DELETE
RESP:0

SET
RESP:911265678
  #2 (permalink)  
Old 11-17-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,927
And of course, the total of 9* will include the count of 9??3 ...


Code:
perl -nle'
  BEGIN { $/ = "</log>"; $, = "\n"; $\ = "\n\n" }
  print /<fullOperation>(.*?):.*<fullResult>(.*?:.*?)[:;]/s;
  if ($1 eq "CREATE") {
    $r = (split /:/, $2)[1];
    $r =~ /^3/ and $r3++;
    $r =~ /^9/ and $r9++;
    $r =~ /9\d{2}3\d{5}/ and $r93++;
    $r =~ /9\d{2}3\d{3}96/ and $r9396++;
    }
  END {
    printf "3* : %d\n9* : %d\n9??3????? : %d\n9??3???96 : %d\n",
    $r3, $r9, $r93, $r9396;
    }' infile

  #3 (permalink)  
Old 11-17-2008
thepurple thepurple is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 134
Oaaaao........its really great. I expecting the output in this way.

I need to add the SET, DELETE logic with the below CREATE. Example-

How many SET with RESP:3*
How many SET with RESP:9*
How many SET with RESP:9??3?????
How many SET with RESP:9??3???96

May i define the script like below-

perl -nle'
BEGIN { $/ = "</log>"; $, = "\n"; $\ = "\n\n" }
print /<fullOperation>(.*?):.*<fullResult>(.*?:.*?)[:;]/s;
if ($1 eq "CREATE") {
$r = (split /:/, $2)[1];
$r =~ /^3/ and $r3++;
$r =~ /^9/ and $r9++;
$r =~ /9\d{2}3\d{5}/ and $r93++;
$r =~ /9\d{2}3\d{3}96/ and $r9396++;
}
if ($1 eq "SET") {
$r = (split /:/, $2)[1];
$r =~ /^3/ and $r3++;
$r =~ /^9/ and $r9++;
$r =~ /9\d{2}3\d{5}/ and $r93++;
$r =~ /9\d{2}3\d{3}96/ and $r9396++;
}

END {
printf "CREATE 3* : %d\nCREATE9* : %d\nCREATE9??3????? : %d\nCREATE9??3???96 : %d\n",
$r3, $r9, $r93, $r9396;

printf "SET3* : %d\nSET9* : %d\nSET9??3????? : %d\nSET9??3???96 : %d\n",
$r3, $r9, $r93, $r9396;

}' infile
  #4 (permalink)  
Old 11-17-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,927
Well,
you'll need more code
Try something like this (some declarations may need to be adjusted):


Code:
perl -wnle'
BEGIN { 
    $/ = "</log>"; 
    our %pats = qw/3* 3 9* 9 9??3????? 9\d{2}3\d{5} 9??3???96 9\d{2}3\d{3}96/;
    } 
  our ($r, $op, $res, $in);    
  if (($op, $r) = /<fullOperation>(.*?):.*<fullResult>(.*?:.*?)[:;]/s) {
    printf "%s\n%s\n\n", $op, $r;
    $res = (split /:/, $r)[1];
    for (keys %pats) {
      $ops{$op}{$_}++ if $res =~ /^$pats{$_}/;
      }
    }
END {
    $, = " ";
    print "-" x 20;
    while (my ($k, $v) = each %ops) {
      printf $k, ": ";
      while (my ($k, $v) = each %$v) {
        print "\t$k : $v\n";
      }
    }
  }' infile


Last edited by radoulov; 11-17-2008 at 04:31 PM..
  #5 (permalink)  
Old 11-18-2008
thepurple thepurple is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 134
It seems to be great. I just test once. got a nice output. I need to test more. Howver, i belive your code correct.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0