Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

awk pipe and system call
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

Report this thread to moderator Post Follow-up to this message
Old Post
uwcssa@gmail.com
03-28-08 11:59 PM


Re: awk pipe and system call
uwcssa@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.

Report this thread to moderator Post Follow-up to this message
Old Post
pk
03-28-08 11:59 PM


Re: awk pipe and system call

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.



Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
03-28-08 11:59 PM


Re: awk pipe and system call
Ed 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.

Report this thread to moderator Post Follow-up to this message
Old Post
pk
03-28-08 11:59 PM


Re: awk pipe and system call

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.


Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
03-28-08 11:59 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:53 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.