S
shane_melville
Hi
I am trying to write a script to return the number of occurences of
certain text/lines/strings in a file. The text is as follows:
Create:subscriber,.........................................................................................................
(blank line)
# sub:success
I have tried the following but it does not work. I am trying to treat
the lines as a string starting with
/Create:subscriber/../sub:success/
but this has not worked. These lines must be together
This is what I have written so far but it does not return the correct
lines
#!/usr/bin/env perl
#use strict;
#use warnings;
sub getlines();
sub getlines1();
my @lines;
my @lines1;
my $lines_ref;
my $lines_ref1;
my $count;
my $count1;
$lines_ref=getlines();
$lines_ref1=getlines1();
@lines=@$lines_ref;
@lines1=@$lines_ref1;
$count=@lines;
$count1=@lines1;
print "The total sub:success count for the file is : $count\n\n
The sub:success strings from the file are as follows: \n\n";
#print join "\n",@lines;
print join "\n",@lines1;
print "The total count for the create subscriber commands is :
$count1\n\n
The create subscriber strings from the file are as follows: \n\n";
#print join "\n",@lines1;
sub getlines()
{
my $file='/data/log/success.log;
open FILE, $file or die "FILE $file NOT FOUND - $!\n";
my @contents=<FILE>;
my @filtered=grep(/sub:success/,@contents);
return \@filtered;
}
sub getlines1()
{
my $file='/data/log/success.log';
my $file='shane.txt';
open FILE, $file or die "FILE $file NOT FOUND - $!\n";
my @contents=<FILE>;
my @filtered1=grep(/Create:subscriber/../sub:success/,@contents);
# my @filtered2=grep(/Create:subscriber/, @contents);
# my @filtered2=grep(/sub:success /,@contents);
return \@filtered1;
}
If anyone can help out drop me a mail
Shane
I am trying to write a script to return the number of occurences of
certain text/lines/strings in a file. The text is as follows:
Create:subscriber,.........................................................................................................
(blank line)
# sub:success
I have tried the following but it does not work. I am trying to treat
the lines as a string starting with
/Create:subscriber/../sub:success/
but this has not worked. These lines must be together
This is what I have written so far but it does not return the correct
lines
#!/usr/bin/env perl
#use strict;
#use warnings;
sub getlines();
sub getlines1();
my @lines;
my @lines1;
my $lines_ref;
my $lines_ref1;
my $count;
my $count1;
$lines_ref=getlines();
$lines_ref1=getlines1();
@lines=@$lines_ref;
@lines1=@$lines_ref1;
$count=@lines;
$count1=@lines1;
print "The total sub:success count for the file is : $count\n\n
The sub:success strings from the file are as follows: \n\n";
#print join "\n",@lines;
print join "\n",@lines1;
print "The total count for the create subscriber commands is :
$count1\n\n
The create subscriber strings from the file are as follows: \n\n";
#print join "\n",@lines1;
sub getlines()
{
my $file='/data/log/success.log;
open FILE, $file or die "FILE $file NOT FOUND - $!\n";
my @contents=<FILE>;
my @filtered=grep(/sub:success/,@contents);
return \@filtered;
}
sub getlines1()
{
my $file='/data/log/success.log';
my $file='shane.txt';
open FILE, $file or die "FILE $file NOT FOUND - $!\n";
my @contents=<FILE>;
my @filtered1=grep(/Create:subscriber/../sub:success/,@contents);
# my @filtered2=grep(/Create:subscriber/, @contents);
# my @filtered2=grep(/sub:success /,@contents);
return \@filtered1;
}
If anyone can help out drop me a mail
Shane