calling AWK from perl question

Discussion in 'Perl Misc' started by wazzu62@hotmail.com, Jun 10, 2006.

  1. Guest

    I am a perl newbie and am trying to convert some shell scripts I have
    written into perl as a learning excercise.

    I have a bash script that has this line in it:

    ksize=`du -sk /files/archive/$period/$day/*$site* | awk '{sum = sum +
    $1} END {print sum}'`

    If I imbed this in a perl script as such:

    $ksize=`du -sk /files/archive/$dates[$cnt]/*$site* | awk '{sum = sum +
    [$1]} END {print sum}'`;

    It generates this error

    awk: cmd. line:1: {sum = sum + []} END {print sum}
    awk: cmd. line:1: ^ parse error
    expr: syntax error

    It seems to not like the $1 variable awk is using.

    Anyone have any ideas how to get around this?

    Thanks in advance.

    wazzu
    , Jun 10, 2006
    #1
    1. Advertising

  2. wrote:
    > I am a perl newbie and am trying to convert some shell scripts I have
    > written into perl as a learning excercise.
    >
    > I have a bash script that has this line in it:
    >
    > ksize=`du -sk /files/archive/$period/$day/*$site* | awk '{sum = sum +
    > $1} END {print sum}'`


    No need to use AWK:

    my $ksize;

    for ( `du -sk /files/archive/$period/$day/*$site*` ) {
    $ksize += ( split )[ 0 ];
    }



    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Jun 10, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. NNTP

    sed awk or perl for this?

    NNTP, Sep 11, 2003, in forum: Perl
    Replies:
    13
    Views:
    3,473
    Alan Connor
    Sep 30, 2003
  2. gorda
    Replies:
    2
    Views:
    542
    Andrew Shitov
    Oct 21, 2003
  3. Thorsten Gottschalk

    awk's NF in Perl

    Thorsten Gottschalk, Mar 5, 2004, in forum: Perl
    Replies:
    1
    Views:
    3,659
    Jim Gibson
    Mar 5, 2004
  4. NNTP
    Replies:
    2
    Views:
    943
    rakesh sharma
    Apr 7, 2004
  5. engineer

    Tool for perl script to awk

    engineer, Jun 14, 2004, in forum: Perl
    Replies:
    1
    Views:
    868
    Joe Smith
    Jun 14, 2004
Loading...

Share This Page