Execute command within AWK - awk
This is a discussion on Execute command within AWK - awk ; Hi,
Is it possible for me to invoke other commands/scripts from gawk. For
example can I invoke "grep" or "wc" from within awk like
gawk '{grep ....}' file 1
"grep" and "wc" are just mentioned as an example. But the ...
-
Execute command within AWK
Hi,
Is it possible for me to invoke other commands/scripts from gawk. For
example can I invoke "grep" or "wc" from within awk like
gawk '{grep ....}' file 1
"grep" and "wc" are just mentioned as an example. But the question is
about invoking commands/scripts from awk.
Thanks,
Prateek
-
Re: Execute command within AWK
Prateek wrote:
> Hi,
> Is it possible for me to invoke other commands/scripts from gawk. For
> example can I invoke "grep" or "wc" from within awk like
>
> gawk '{grep ....}' file 1
>
> "grep" and "wc" are just mentioned as an example. But the question is
> about invoking commands/scripts from awk.
>
> Thanks,
> Prateek
>
Yes:
$ awk 'BEGIN{system("echo hello")}'
hello
$ awk 'BEGIN{print "echo hello" | "/bin/sh" }'
hello
It's usually a sign that you're very confused about the best way to
design your script though....
Ed.
-
Re: Execute command within AWK
On Wed, 06 Jun 2007 12:36:14 -0700, Prateek <prateek.a@>
wrote:
>Hi,
>Is it possible for me to invoke other commands/scripts from gawk. For
>example can I invoke "grep" or "wc" from within awk like
>
>gawk '{grep ....}' file 1
>
>"grep" and "wc" are just mentioned as an example. But the question is
>about invoking commands/scripts from awk.
>
grep is a poor example - wc is only somewhat less so because of the
large overlap in functionality.
However, wget is a good example - this is composite code from several
scripts:
WgetCommand = "wget -t 3 -T 30 -O- -U \"Mozilla/5.0
(Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219
Firefox/2.0.0.2\" http://www.wire-heads.com/istrip/ 2>"
StdErrFile = Array[ 4 ] ".response"
WgetCommand = WgetCommand StdErrFile
while( ( WgetCommand | getline ) > 0 ) {
if( !x ) {
if( match( tolower( $0 ),
/comic?[sx]?[0-9]?[\/=]([a-z0-9\-_\/]+)\./, Arr ) ) x = Arr[1]
}
(Actually, that is not working code because that test doesn't go with
that URL.)
--
T.E.D. (tdavis@gearbox.maem.umr.edu)
Remove "gearbox.maem." from address - that one is dead
-
Re: Execute command within AWK
Ed Morton wrote:
> Prateek wrote:
>> Hi,
>> Is it possible for me to invoke other commands/scripts from gawk. For
>> example can I invoke "grep" or "wc" from within awk like
>>
>> gawk '{grep ....}' file 1
>>
>> "grep" and "wc" are just mentioned as an example. But the question is
>> about invoking commands/scripts from awk.
>>
>> Thanks,
>> Prateek
>>
>
> Yes:
>
> $ awk 'BEGIN{system("echo hello")}'
> hello
> $ awk 'BEGIN{print "echo hello" | "/bin/sh" }'
> hello
>
> It's usually a sign that you're very confused about the best way to
> design your script though....
>
> Ed.
Just one note, for Prateek, not all implementations of awk have the "system"
command. Get GNU-awk.
--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GE d+(-) s+: a@ C+ ULAHS++$ P- L+>++ E--- W++ N++ o !K w--(+) O- M?>+ V? PS+
PE+(++) Y+ PGP- t+ 5 X R !tv b+ DI(+) D G e++ h---- r+++@ y++++
------END GEEK CODE BLOCK------
Similar Threads
-
By Application Development in forum Java
Replies: 4
Last Post: 09-13-2007, 10:04 AM
-
By Application Development in forum DOTNET
Replies: 3
Last Post: 04-29-2007, 06:12 AM
-
By Application Development in forum DOTNET
Replies: 4
Last Post: 03-22-2006, 08:16 AM
-
By Application Development in forum Inetserver
Replies: 1
Last Post: 10-22-2003, 09:43 AM
-
By Application Development in forum Inetserver
Replies: 1
Last Post: 10-22-2003, 07:47 AM