calling AWK from perl question

W

wazzu62

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
 
J

John W. Krahn

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top