Sponsored Content
Top Forums Shell Programming and Scripting [Perl] Same entries in file, but treat them different. Post 302521692 by Klashxx on Thursday 12th of May 2011 03:49:28 AM
Old 05-12-2011
You can use a flag to mark the first.
Code:
#!/bin/perl -w

use strict;

my @log_lines;
my $log_line;

my $flag = 0;
my $SortTable_Start = 0;
my $SortTable_End = 0;
my $SortTable_Duration = 0;
my $LoadTable_Start = 0;
my $LoadTable_End = 0;
my $LoadTable_Duration = 0;
my $SortTable1_Start = 0;
my $SortTable1_End = 0;
my $SortTable1_Duration = 0;
my $LoadTable1_Start = 0;
my $LoadTable1_End = 0;
my $LoadTable1_Duration = 0;
my $SortTable2_Start = 0;
my $SortTable2_End = 0;
my $SortTable2_Duration = 0;
my $LoadTable2_Start = 0;
my $LoadTable2_End = 0;
my $LoadTable2_Duration = 0;
my $IndexTable_Start = 0;
my $IndexTable_End = 0;
my $IndexTable_Duration = 0;
my $AnalyzeTable_Start = 0;
my $AnalyzeTable_End = 0;
my $AnalyzeTable_Duration = 0;

open (LOGOUT, "<log.out");
@log_lines = <LOGOUT>;

foreach $log_line (@log_lines) {

 if ( $log_line =~ m/Sorting of Table data file started/ ) {
      $SortTable_Start = $1 if ( $log_line =~ m/(\d+)/ );
    }
 if ( $log_line =~ m/Starting Table table loading/ ) {
      $LoadTable_Start = $1 if ( $log_line =~ m/(\d+)/ );
      $SortTable_End = $LoadTable_Start;
    }
 if ( $log_line =~ m/Sorting of Table1 data file started/ ) {
      $SortTable1_Start = $1 if ( $log_line =~ m/(\d+)/ );
      $LoadTable_End = $SortTable1_Start;
    }
 if ( $log_line =~ m/Starting Table table loading/ ) {
      $LoadTable1_Start = $1 if ( $log_line =~ m/(\d+)/ );
      $SortTable1_End = $LoadTable1_Start;
    }
 if ( $log_line =~ m/Sorting of Table2 data file started/ ) {
      $SortTable2_Start = $1 if ( $log_line =~ m/(\d+)/ );
      $LoadTable1_End = $SortTable2_Start;
    }
 if ( $log_line =~ m/Starting Table table loading/ && ! $flag) {
      $flag=1;
      $LoadTable2_Start = $1 if ( $log_line =~ m/(\d+)/ );
      $SortTable2_End = $LoadTable2_Start;
    }
 if ( $log_line =~ m/Creating Table indexes/ ) {
      $IndexTable_Start = $1 if ( $log_line =~ m/(\d+)/ );
      $LoadTable2_End = $IndexTable_Start;
    }
 if ( $log_line =~ m/Analyzing table Table/ ) {
      $AnalyzeTable_Start = $1 if ( $log_line =~ m/(\d+)/ );
      $IndexTable_End = $AnalyzeTable_Start;
    }
 if ( $log_line =~ m/End of table_load/ ) {
      $AnalyzeTable_End = $1 if ( $log_line =~ m/(\d+)/ );
    }
}
close (LOGOUT);

$SortTable_Duration = $SortTable_End - $SortTable_Start;
$SortTable_Duration = sprintf ("%.0f", ($SortTable_Duration / 60));
$LoadTable_Duration = $LoadTable_End - $LoadTable_Start;
$LoadTable_Duration = sprintf ("%.0f", ($LoadTable_Duration / 60));
$SortTable1_Duration = $SortTable1_End - $SortTable1_Start;
$SortTable1_Duration = sprintf ("%.0f", ($SortTable1_Duration / 60));
$LoadTable1_Duration = $LoadTable1_End - $LoadTable1_Start;
$LoadTable1_Duration = sprintf ("%.0f", ($LoadTable1_Duration / 60));
$SortTable2_Duration = $SortTable2_End - $SortTable2_Start;
$SortTable2_Duration = sprintf ("%.0f", ($SortTable2_Duration / 60));
$LoadTable2_Duration = $LoadTable2_End - $LoadTable2_Start;
$LoadTable2_Duration = sprintf ("%.0f", ($LoadTable2_Duration / 60));
$IndexTable_Duration = $IndexTable_End - $IndexTable_Start;
$IndexTable_Duration = sprintf ("%.0f", ($IndexTable_Duration / 60));
$AnalyzeTable_Duration = $AnalyzeTable_End - $AnalyzeTable_Start;
$AnalyzeTable_Duration = sprintf ("%.0f", ($AnalyzeTable_Duration / 60));

printf "SortTable_Duration : $SortTable_Duration minutes\n";
printf "LoadTable_Duration : $LoadTable_Duration minutes\n";
printf "SortTable1_Duration : $SortTable1_Duration minutes\n";
printf "LoadTable1_Duration : $LoadTable1_Duration minutes\n";
printf "SortTable2_Duration : $SortTable2_Duration minutes\n";
printf "LoadTable2_Duration : $LoadTable2_Duration minutes\n";
printf "IndexTable_Duration : $IndexTable_Duration minutes\n";
printf "AnalyzeTable_Duration : $AnalyzeTable_Duration minutes\n";

 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - treat multiple delimiters as one

Is there anyway to get awk to treat multiple delimiters as one? Particularly spaces... (6 Replies)
Discussion started by: peter.herlihy
6 Replies

2. Shell Programming and Scripting

How to get the difference between dates?Can i treat as string?

Hi All , I have an output value with two columns like this... Days User 10 A 500 B 1 C How i can compare the first column value and passing the user name as parameter? For example : while read -r days If (days<=30) ; then value=days/30 x100 ... (3 Replies)
Discussion started by: EDBGSK
3 Replies

3. Shell Programming and Scripting

while read loop w/ a nested if statement - doesn't treat each entry individually

Hi - Trying to take a list of ldap suffixes in a file, run an ldapsearch command on them, then run a grep command to see if it's a match, if not, then flag that and send an email alert. The list file (ldaplist) would look like - *********** o=company a o=company b *********** **... (7 Replies)
Discussion started by: littlefrog
7 Replies

4. UNIX for Dummies Questions & Answers

make script treat * as a regular character

I need a script that reads the out put of a command (softwareupdate --list) and will tally up the number of asterisks in the output and tell me how many there were. How do I go about getting my script to treat asterisks as a regular character and not a wildcard or some other operator? (8 Replies)
Discussion started by: glev2005
8 Replies

5. UNIX for Dummies Questions & Answers

doubt to treat plaintext script

Hi everyone! first of all thank you all for the forum. My question is, is there a bash or java program, which addresses the existing text in the html that is visible in the web page for editing by another string, eg name1: flakjsdlñfjas Name of father: fdfjaksdfjskdfsd Well it... (1 Reply)
Discussion started by: xavilito
1 Replies

6. Shell Programming and Scripting

Perl's buffered I/O is causing me to miss latest log file entries in log colorizer. How to fix?

I've been finding myself using a log file colorizer written in perl to reformat and colorize the output from many different programs. Mainly, however, I use it to make the output from "tail -f" commands more readable. The base perl script I use is based on "colorlogs.pl" available from the... (1 Reply)
Discussion started by: rcsteiner
1 Replies

7. Shell Programming and Scripting

awk script modification - treat certain files differently

awk 'BEGIN{OFS=","} FNR == 1 {if (NR > 1) {print fn,fnr,nl} fn=FILENAME; fnr = 1; nl = 0} {fnr = FNR} /UNUSUAL/ && /\.gz/ ~ /FILENAME/ {nl++} <'{system ("gunzip -cd FILENAME")}' END ... (2 Replies)
Discussion started by: SkySmart
2 Replies

8. Shell Programming and Scripting

Treat Command Output as a File

Hi. Before I've post this question, I have spent hours looking for the solutions but to no avail. Because I think it is possible but I just don't know what is the right keyword to search for. Ok, basically what I want to achieve is really simple. It's just that I don't want to write... (20 Replies)
Discussion started by: aimy
20 Replies
All times are GMT -4. The time now is 10:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy