command line and awk -f test not the same ? 
Author Message
 command line and awk -f test not the same ?

'ello !
I'm analyzing ( i try ... ) my net-acct - logfiles from the
command line:
BEGIN { sum = 0 } $8 == "eth0" && (( $3 ~ /192\.168\.210\./ ) || ( $5
~ /192\.169\.210\./ )) { sum += $7 } END { print "Traffic :"
cortech/1024 "k" }
The Result is about 1450k.
When running with "awk -f sum.awk /var/log/net-acct" the
result is about 650000k.
I just copy & pasted this line into sum.awk.
$8 ist eth0 or eth1.
$3/$5 are source/destination ip.

Does anybody have a hint ??

Thanks,
    Sascha

--
Ripley -- a Linux-based wearable computer
(LinuxWeeklyNews on 07Jun2001)



Sun, 04 Jan 2004 00:04:59 GMT  
 command line and awk -f test not the same ?

Quote:
> 'ello !
> I'm analyzing ( i try ... ) my net-acct - logfiles from the
> command line:
> BEGIN { sum = 0 } $8 == "eth0" && (( $3 ~ /192\.168\.210\./ ) || ( $5
> ~ /192\.169\.210\./ )) { sum += $7 } END { print "Traffic :"
> cortech/1024 "k" }
> The Result is about 1450k.
> When running with "awk -f sum.awk /var/log/net-acct" the
> result is about 650000k.
> I just copy & pasted this line into sum.awk.
> $8 ist eth0 or eth1.
> $3/$5 are source/destination ip.

> Does anybody have a hint ??

> Thanks,
>     Sascha

1) You don't need to initialize sum: uninitialized awk variables are
automatically zero or null depending on context.

2) Try:

$8 == "eth0" && (( $3 ~ /192\.168\.210\./ ) || ( $5~
/192\.169\.210\./ )) {
    sum += $7

Quote:
}

END { print "Traffic :" sum/1024 "k" }

? typo in your original ^^^^ here?
HTH
--
Peter S Tillier
peter dot tillier at btinternet dot com
To reply direct to me please use the above address
not the "Reply To" which activates a spam trap.



Sun, 04 Jan 2004 02:32:50 GMT  
 command line and awk -f test not the same ?


Quote:


>> 'ello !
>> I'm analyzing ( i try ... ) my net-acct - logfiles from the
>> command line:
>> BEGIN { sum = 0 } $8 == "eth0" && (( $3 ~ /192\.168\.210\./ ) || (
>> $5 ~ /192\.169\.210\./ )) { sum += $7 } END { print "Traffic :"
>> cortech/1024 "k" }
>> The Result is about 1450k.
>> When running with "awk -f sum.awk /var/log/net-acct" the
>> result is about 650000k.
>> I just copy & pasted this line into sum.awk.
>> $8 ist eth0 or eth1.
>> $3/$5 are source/destination ip.

>> Does anybody have a hint ??

>> Thanks,
>>     Sascha

>1) You don't need to initialize sum: uninitialized awk variables are
>automatically zero or null depending on context.

That's nice of awk.

Quote:
>2) Try:

>$8 == "eth0" && (( $3 ~ /192\.168\.210\./ ) || ( $5~
>/192\.169\.210\./ )) {
>    sum += $7
>}
>END { print "Traffic :" sum/1024 "k" }

>? typo in your original ^^^^ here?

Oh, i think awk is very pedantic with where brackets have to be ...
Yes, there's a typo, but that came in while writing this posting.
But i found another typo:
The second RFC-Adress is 192.169... *argh*
It's one thing to look at your own code and another to look
at anotherone's code ...

But thanks, so i found the typo and i can format that
awk stuff nicier.

Bye,
      Sascha



Mon, 05 Jan 2004 17:34:04 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing command line variables to AWK in shell script

2. Awk Command-line Variables - Thanks!

3. Awk Command-Line Variables

4. Command line length - awk on a PC

5. Command-Line AWK

6. Command line variable assignment in awk

7. pass regexp to awk on command line

8. Command line options in awk scripts?

9. Help passing command line parameters to awk scripts

10. THANKS: Help passing command line parameters to awk script

11. Portable test of command line arguments?

12. gnat3.10 Win95 saya command line not part of Ada

 

 
Powered by phpBB® Forum Software