Hi All,
Below is the contents of a log file.I need to collect the time when LP is disabled.
ie( 07:12:29.69) and the time LP is enabled(07:13:57.08),and find the difference betwwen two.Now I can match the word "Com: LP is Disabled" in the file but
how to take that particular time which is six lines above it.
Note:We cannot make any comparison using lp/2 as it keeps on changing.
can any one tell me how to do this?
contents of file::
Lp/2; 2007-01-03 07:12:29.69
SET critical processing underlyingResourceUnavail 70120200
ADMIN: unlocked OPER: disabled USAGE: idle
AVAIL: dependency PROC: CNTRL:
ALARM: critical STBY: notSet UNKNW: false
Id: C8 Rel: Shelf Card/2
Com: LP is Disabled
Int: 0/0/2/11244; pcsLpMgr.cc; 4385;
Shelf Card/2; 2007-01-03 07:13:22.02
CLR cleared equipment processorProblem 70120100
ADMIN: unlocked OPER: enabled USAGE: idle
AVAIL: PROC: CNTRL:
ALARM: STBY: notSet UNKNW: false
Id: CB Rel:
Com: Card is Enabled
Int: 0/0/2/11244; pcsCardMgr.cc; 9849;
114>
Lp/2; 2007-01-03 07:13:57.08
CLR cleared processing underlyingResourceUnavail 00000000
ADMIN: unlocked OPER: enabled USAGE: active
AVAIL: PROC: CNTRL:
ALARM: STBY: providingServ UNKNW: false
Id: CD Rel: Shelf Card/2
Com: LP is Enabled
Int: 0/0/2/11244; pcsLpMgr.cc; 4385; U
4 1359
collect the time first then check if it's disable or enable.
or might be easier to read the file backwards. Then you get your enabled/disabled tokens first. Can you install perl modules? There is a module for reading files backwards. http://search.cpan.org/~uri/File-Rea...adBackwards.pm
if not and the file isn't gigantic you can read it into an array and reverse the array.
@kriz4321 - @file = (
-
"Lp/2; 2007-01-03 07:12:29.69\n",
-
"SET critical processing underlyingResourceUnavail 70120200\n",
-
"ADMIN: unlocked OPER: disabled USAGE: idle\n",
-
"AVAIL: dependency PROC: CNTRL:\n",
-
"ALARM: critical STBY: notSet UNKNW: false\n",
-
"Id: C8 Rel: Shelf Card/2\n",
-
"Com: LP is Disabled\n",
-
"Int: 0/0/2/11244; pcsLpMgr.cc; 4385;\n",
-
"\n",
-
"\n",
-
"Shelf Card/2; 2007-01-03 07:13:22.02\n",
-
"CLR cleared equipment processorProblem 70120100\n",
-
"ADMIN: unlocked OPER: enabled USAGE: idle\n",
-
"AVAIL: PROC: CNTRL:\n",
-
"ALARM: STBY: notSet UNKNW: false\n",
-
"Id: CB Rel:\n",
-
"Com: Card is Enabled\n",
-
"Int: 0/0/2/11244; pcsCardMgr.cc; 9849;\n",
-
"\n",
-
"\n",
-
"\n",
-
"114>\n",
-
"Lp/2; 2007-01-03 07:13:57.08\n",
-
"CLR cleared processing underlyingResourceUnavail 00000000\n",
-
"ADMIN: unlocked OPER: enabled USAGE: active\n",
-
"AVAIL: PROC: CNTRL:\n",
-
"ALARM: STBY: providingServ UNKNW: false\n",
-
"Id: CD Rel: Shelf Card/2\n",
-
"Com: LP is Enabled\n",
-
"Int: 0/0/2/11244; pcsLpMgr.cc; 4385; U\n",
-
);
-
-
sub printState {
-
my($whichTime, $whichLp, $state) = @_;
-
-
printf("[$whichTime] Lp$whichLp -> $state\n");
-
}
-
-
for $line ( @file ) {
-
$state = "";
-
-
if ( $line =~ /^Lp/ ) {
-
($whichLp, $whichTime) = ($line =~ /^^Lp\/([\d+]);\s+[\d-]+\s+(.*)/g);
-
}
-
elsif ( $line =~ /^ADMIN.*enabled\s+USAGE:\s+active.*/ ) {
-
printState($whichTime, $whichLp, "enabled");
-
}
-
elsif ( $line =~ /^ADMIN.*disabled\s+USAGE:\s+idle.*/ ) {
-
printState($whichTime, $whichLp, "disabled");
-
}
-
}
Substitute the code
by your input method of reading the file.
Greetz, Doc
here is another suggestion: - my @log = ();
-
open(FH,'log.txt') or die "$!";
-
while(<FH>){
-
push @log,$1 if (m|^Lp/2;\s+\S+\s+(\S+)$|);
-
push @log,$1 if (m/^Com: LP is (Enabled|Disabled)/);
-
}
-
close(FH);
-
@log = reverse @log;
-
-
my ($e,$d) =(0,0);
-
foreach my $i (0..$#log-1) {
-
if ($log[$i] eq 'Enabled'){
-
$e = $log[$i+1];
-
}
-
elsif ($log[$i] eq 'Disabled') {
-
$d = $log[$i+1];
-
}
-
if ($e && $d) {
-
convert them into total seconds
-
subtract to get difference
-
reset $e and $d if there will be more
-
}
-
}
admitedly, I did not put much thought into this, so it probably can be improved upon.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: gsv2com |
last post by:
One of my weaknesses has always been pattern matching. Something I
definitely need to study up on and maybe you guys can give me a pointer
here.
I'm looking to remove all of this code and just...
|
by: Thomas Reichelt |
last post by:
Moin,
short question: is there any language combining the syntax, flexibility and
great programming experience of Python with static typing? Is there a
project to add static typing to Python?
...
|
by: Greg Lindstrom |
last post by:
Hello-
I'm running Python 2.2.3 on Windows XP "Professional" and am reading a file
wit 1 very long line of text (the line consists of multiple records with no
cr/lf). What I would like to do is...
|
by: Xah Lee |
last post by:
# -*- coding: utf-8 -*-
# Python
# Matching string patterns
#
# Sometimes you want to know if a string is of
# particular pattern. Let's say in your website
# you have converted all images...
|
by: Henry |
last post by:
I have a table that stores a list of zip codes using a varchar column type,
and I need to perform some string prefix pattern matching search. Let's say
that I have the columns:
94000-1235
94001...
|
by: bpontius |
last post by:
The GES Algorithm
A Surprisingly Simple Algorithm for Parallel Pattern Matching
"Partially because the best algorithms presented in the literature
are difficult to understand and to implement,...
|
by: olaufr |
last post by:
Hi,
I'd need to perform simple pattern matching within a string using a
list of possible patterns. For example, I want to know if the substring
starting at position n matches any of the string I...
|
by: Jim Lewis |
last post by:
Anyone have experience with string pattern matching?
I need a fast way to match variables to strings. Example:
string - variables
============
abcaaab - xyz
abca - xy
eeabcac - vxw
x...
|
by: Ole Nielsby |
last post by:
First, bear with my xpost. This goes to
comp.lang.c++
comp.lang.functional
with follow-up to comp.lang.c++
- I want to discuss an aspect of using C++ to implement a
functional language, and...
|
by: pramodkh |
last post by:
Hi All
I am trying to match a pattern in a file and insert a line. If the pattern matches then insert a line before the matching pattern line.
for example,
I have the following content in a...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |