Output: in excel file, Column1(date) Column2(Number of occurences)
My excel file should also contain all the dates, if on any particular day, STATUS keyword is not found, it will show count as 0
Please help me ASAP. I am in very urgent need of this shell script.
Why do you need bash specifically perl can be called within a bash script, it's just another utility, a very powerful one that you can use to write complex programs in, but also a command line utility.
Perl allows you to call a shell command in three ways, exec, system and with backticks or using the qx(), quote executable, operator
exec ("$ENV{HOME}/bin/my_script.sh --f - l -a - g -s");
system ("$ENV{HOME}/bin/my_script.sh -f - l -a - g -s");
$result = qx($ENV{HOME}/bin/my_script.sh -f - l -a - g -s);
exec hands control over to the called operation and the entire process dies with the called script, whereas system forks a new process and waits for it to complete. The qx operator is like system except it returns the output of the command which allows us to assign it.
Actually, I have no idea how to write the script. This is actually my first time.
I wrote the code like this:
#!/usr/local/bin/perl
MAIN:
{
while(<>)
{
$counts{$1} = 0 if (/\[(\d{4}-\d{2}-\d{2})/ ) && (! defined $cou
nts{$1})
$counts{$1}++ if /\[(\d{4}-\d{2}-\d{2}).+STATUS/;
}
for $date (sort keys %counts)
{
print "$date , $counts{$date}\n";
}
}
On running the code, I am getting following error:
bash-3.00$ perl test.pl license.log > status.log
Scalar found where operator expected at test.pl line 9, near ")
$counts"
(Missing operator before $counts?)
syntax error at test.pl line 9, near ")
$counts"
syntax error at test.pl line 9, near "++ if"
syntax error at test.pl line 16, near "}"
Execution of test.pl aborted due to compilation errors.
#!/usr/local/bin/perl
use strict;
use warnings;
my %counts;
while(<>){
$counts{$1} = 0 if (/\[(\d{4}-\d{2}-\d{2})/ ) && (! defined $counts{$1});
$counts{$1}++ if /\[(\d{4}-\d{2}-\d{2}).+STATUS/;
}
for my $date (sort keys %counts){
print "$date , $counts{$date}\n";
}