I have an array in perl and each variable in the array contains the data in the below format
Now I need to check the below variable w.r.t system month I need to store the date and time(Tue Aug 7 03:54:12 2012) from the below data into file if contains only 'Aug' .
Created By = sripathi
Server Name = dysp001
time = Tue Aug 7 03:54:12 2012
Node = mumgwmpls2335.net.hca.com
Could anyone please let me know how to store the time(Tue Aug 7 03:54:12 2012).
Thanks in advance....
Regards,
GS
---------- Post updated 09-03-12 at 12:00 AM ---------- Previous update was 09-02-12 at 11:51 PM ----------
Actually the problem is that if the above data is a text file then we can do it easily but I have the data stored in a variable and there lies the problem.
Could anyone please let me know how to solve this.
but your code doesnt suit my requirement.In your code, you mentioned time as a variable.
$time = "Tue Aug 7 03:54:12 2012"; if ($time =~ m/aug/i) {print "$time\n;"} Tue Aug 7 03:54:12 2012
But if you look into my below data...time is not a variable. It is just a text inside the data.
### below mentioned data is not in a text file... It is stored in a array variable
Created By = sripathi
Server Name = dysp001
time = Tue Aug 7 03:54:12 2012
Node = mumgwmpls2335.net.hca.com
for better understanding ...
the above mentioned data is stored in a variable say $data.
Now I need to search for the aug month. If the data contains aug then I need to store ONLY the "Tue Aug 7 03:54:12 2012" into a separate variable.
my $data="Created By = sripathi Server Name = dysp001 time = Tue Aug 7 03:54:12 2012 Node = mumgwmpls2335.net.hca.com";
if($data=~/aug/i){
$res=$data;
$res=~s/.*time =(.*)Node =.*/$1/;
print "Original:$data\nResult:$res\n";
}
Could you please format the query for the below data.
The output should be same..
I need to copy the data and time(Tue Aug 7 03:54:12 2012) to another variable....
Created By = sumitp
ServerName = dysp001
FirstOccurrence = Tue Aug 7 03:54:12 2012
ServerSerial = 145924222
Summary = DEVICE HAS STOPPED RESPONDING
Customer = TELECOM
Node = mumabcsbp5034.net.adp.com
Severity = Critical
open(FILE,"<filename");
while(<FILE>) {
my $data=$_;
chomp($data);
if($data=~/ aug /i){
$res=$data;
$res=~s/.* = (.*)/$1/;
print "Original:$data\nResult:$res\n";
}
# Do your other stuff here with the date and time.
}
close(FILE);
Here I am assuming that the data is in a file called 'filename' and read that file and do other stiff with that date.