I have a very simple script where I�m trying to print a line from status.dat file.
The script will find the line containing "servicestatus", and I want to print the content of the next line.
For example, the file contains this text:
servicestatus {
hostname = Obelix
What i want to print is "hostname = Obelix"
Could you help?
Here goes the code. I want to replace "PRINT LINE AFTER THAT" with the necessary code to print the second line after "servicestatus."
#!/usr/bin/perl -w
open my $logfile, 'status.dat' or die "I couldn't get at status.dat: $!";
for my $line (<$logfile>) {
if $line =~ /^servicestatus/;
"PRINT LINE AFTER THAT"
}
#!/usr/bin/perl
use warnings;
use strict;
open (LOG,"<","status.dat") or die "I couldn't get at status.dat: $!";
while (<LOG>) {
chomp ($_);
if ($_ =~ /^servicestatus/){
my $nextline=<LOG>;
print "$nextline";
}
}
#!/usr/bin/perl -w
open LOGFILE, 'status.dat' or die "I couldn't get at status.dat: $!";
while (<LOGFILE>) {
print $prev if /^service name = test/;
$prev=$_
}