Code Comments
Programming Forum and web based access to our favorite programming groups.i have two problems with awk:
first, the following works on my system, which shows system usage
iostat 2 | awk '{print $1}'
However, the following seems never gets written to the log file
iostat 2 | awk '{print $1}' > log
It may gets buffered inside awk, is there a way to turn auto buffer
off?
Second problem is that I found it is impossible to send variables to
system calls:
the following works inside awk script:
system( "echo " $0);
However, the following never works:
BEGIN{ myvar1=0;}
{ myvar2 =1;
system("echo " $myvar1 $myvar2);
Any ideas? thanks a bunch
Post Follow-up to this messageuwcssa@gmail.com wrote:
> However, the following never works:
>
> BEGIN{ myvar1=0;}
> { myvar2 =1;
> system("echo " $myvar1 $myvar2);
>
> Any ideas? thanks a bunch
- use myvar1 and myvar2, without the "$";
- put a space between the variables:
$ echo "blah" | awk 'BEGIN {myvar1=0}
{myvar2=1;system("echo "myvar1" "myvar2)}'
0 1
--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
Post Follow-up to this message
On 3/28/2008 10:27 AM, pk wrote:
> uwcssa@gmail.com wrote:
>
>
>
>
> - use myvar1 and myvar2, without the "$";
Not if he's trying to get $0 and $1.
> - put a space between the variables:
>
> $ echo "blah" | awk 'BEGIN {myvar1=0}
> {myvar2=1;system("echo "myvar1" "myvar2)}'
> 0 1
He should still be seeing the concatenation of $0 and $1 with what he had
(though all he said was that it "never works" so maybe that IS what he's see
ing
and it's just not what he expected).
Ed.
Post Follow-up to this messageEd Morton wrote: > > Not if he's trying to get $0 and $1. > > He should still be seeing the concatenation of $0 and $1 with what he had > (though all he said was that it "never works" so maybe that IS what he's > seeing and it's just not what he expected). Ah yes, that's another possibility. Mine was just my interpretation of the problem, and admittedly he did not provide too much context or details. -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome.
Post Follow-up to this message
On 3/28/2008 9:59 AM, uwcssa@gmail.com wrote:
> i have two problems with awk:
>
> first, the following works on my system, which shows system usage
>
> iostat 2 | awk '{print $1}'
>
> However, the following seems never gets written to the log file
>
> iostat 2 | awk '{print $1}' > log
>
> It may gets buffered inside awk, is there a way to turn auto buffer
> off?
Take a look at this thread:
http://tinyurl.com/33ua89
Regards,
Ed.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.