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 ...

+ Reply to Thread
Results 1 to 4 of 4

Execute command within AWK

  1. Default 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


  2. Default 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.

  3. Default 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

  4. Default 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------

+ Reply to Thread

Similar Threads

  1. Execute OS command
    By Application Development in forum Java
    Replies: 4
    Last Post: 09-13-2007, 10:04 AM
  2. How do I execute a dos command from a .NET VC++ program
    By Application Development in forum DOTNET
    Replies: 3
    Last Post: 04-29-2007, 06:12 AM
  3. .net won't execute Sql Command
    By Application Development in forum DOTNET
    Replies: 4
    Last Post: 03-22-2006, 08:16 AM
  4. RUN/execute a Command-Line command from an ASP page.
    By Application Development in forum Inetserver
    Replies: 1
    Last Post: 10-22-2003, 09:43 AM
  5. RUN/execute a Command-Line command from an ASP page.
    By Application Development in forum Inetserver
    Replies: 1
    Last Post: 10-22-2003, 07:47 AM