For Programmers: Free Programming Magazines  


Home > Archive > AWK > June 2007 > Execute command within AWK









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Execute command within AWK
Prateek

2007-06-07, 9:57 pm

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,
Prat

Ed Morton

2007-06-07, 9:57 pm

Prat 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,
> Prat
>


Yes:

$ awk 'BEGIN{system("echo hello")}'
hello
$ awk 'BEGIN{print "echo hello" | "/bin/sh" }'
hello

It's usually a sign that you're very about the best way to
design your script though....

Ed.
Ted Davis

2007-06-07, 9:57 pm

On Wed, 06 Jun 2007 12:36:14 -0700, Prat <prat.a@gmail.com>
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
SiKing

2007-06-11, 7:57 am

Ed Morton wrote:
> Prat wrote:
>
> Yes:
>
> $ awk 'BEGIN{system("echo hello")}'
> hello
> $ awk 'BEGIN{print "echo hello" | "/bin/sh" }'
> hello
>
> It's usually a sign that you're very about the best way to
> design your script though....
>
> Ed.


Just one note, for Prat, 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------
Hadick4

2007-06-13, 2:10 am

Hilary Swank Gay gallery!
http://www.WatchingTheTube.com/WatchTube?watch=1673286

Ashlee Simpson , Her first lesbian sex!
http://www.WatchingTheTube.com/player.asp?watch=1673286

Mariah Carey sex parties - coed parties as you never saw them!
http://www.WatchingTheTube.com/Player.mpeg?id=1673286

Carmen Electra 16 - AmateurThumbs!
http://www.WatchingTheTube.com/watch?clip=1673286

Paris Hilton Shows Tiny Tits & Ass!
http://www.WatchingTheTube.com/watch?q=1673286

free sex video trailer teen sex video movie clip ebony sex video celebrity clip free sex video britney sex video
http://343-sex-video.info/porn-star-sex-video.html http://343-sex-video.info/nude-celeb-sex-video.html http://343-sex-video.info/clip-indi...-sex-video.html http://343-sex-video.info/geil-gratis-sex-video.html http://343-sex-video.info/gay-group-sex-video.html
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com