Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Perl Programming Language

Executing awk from perl script


I'm new to perl and have the following line that I try to execute:

...
my $hm = `date +%H:%M --date "1 minute ago"`;
my $fname = `date +AppName_stats.log.%Y-%m-%d --date "1 days ago"`;

my $hits = `find /logs/server_name0?/dir/. -name "$fname*" -exec
gunzip -c {} ;\ | /grep SearchStr | /bin/awk -F","
'{if(substr($1,12,5)~hmpoint)print $3}' hmpoint=$hm | /bin/awk '{tot+=
$1}END{print tot}'`;

When I run this I get all kinds of complaints on the $hits line.  I've
tried various modifications, but can't seem to get it to work.  Any
idea of what's wrong here?

Thanks.

On 24 Mar 2007 09:55:17 -0700, "AyOut" <mort@gmail.com> wrote:

>my $hm = `date +%H:%M --date "1 minute ago"`;
>my $fname = `date +AppName_stats.log.%Y-%m-%d --date "1 days ago"`;

>my $hits = `find /logs/server_name0?/dir/. -name "$fname*" -exec
>gunzip -c {} ;\ | /grep SearchStr | /bin/awk -F","
>'{if(substr($1,12,5)~hmpoint)print $3}' hmpoint=$hm | /bin/awk '{tot+=
>$1}END{print tot}'`;

>When I run this I get all kinds of complaints on the $hits line.  I've
>tried various modifications, but can't seem to get it to work.  Any
>idea of what's wrong here?

Probably, trying to use Perl as a shell scripting language. In which
case you'd better write a shell script in the first place. There's
"almost" nothing awk can do that Perl can't. So please describe your
task instead. Someone will come up with an example Perl version.

Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

AyOut wrote:
> I'm new to perl and have the following line that I try to execute:

> ...
> my $hm = `date +%H:%M --date "1 minute ago"`;
> my $fname = `date +AppName_stats.log.%Y-%m-%d --date "1 days ago"`;

> my $hits = `find /logs/server_name0?/dir/. -name "$fname*" -exec
> gunzip -c {} ;\ | /grep SearchStr | /bin/awk -F","
> '{if(substr($1,12,5)~hmpoint)print $3}' hmpoint=$hm | /bin/awk '{tot+=
> $1}END{print tot}'`;

> When I run this I get all kinds of complaints on the $hits line.  I've
> tried various modifications, but can't seem to get it to work.  Any
> idea of what's wrong here?

In Perl you would write that as:

use POSIX 'strftime';
use File::Find;
use Compress::Zlib;

my $hm    = strftime '%H:%M', localtime $^T - 60;
my $fname = strftime 'AppName_stats.log.%Y-%m-%d', localtime $^T - 86400;

my $hits;
find sub {
    return unless /\A\Q$fname/;

    my $gz = gzopen( $_, 'rb' ) or die "Cannot open $_: $gzerrno\n";

    while ( $gz->gzreadline( my $line ) > 0 ) {

        if ( $line =~ /SearchStr/ && substr( $line, 11, 5 ) eq $hm ) {
            $hits += ( split /,/, $line )[ 2 ];
            }
        }

    die "Error reading from $_: $gzerrno\n" if $gzerrno != Z_STREAM_END;
    $gz->gzclose();

    }, glob '/logs/server_name0?/dir';

> Thanks.

You're welcome.

John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc