can't call a shell script from within awk

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jabbah
    New Member
    • Nov 2007
    • 63

    can't call a shell script from within awk

    i can execute echo from within awk like so:
    Code:
    echo asdf jkl asdf \
    | awk ' /jkl/ { sub(/jkl/,echo "X(&)") } {print}'
    asdf X(jkl) asdf
    but if i want to execute another shell script
    Code:
    cat ~/bin/doit
    #!/bin/bash
    echo -n KKK
    like so:
    Code:
    echo asdf jkl asdf \
    | awk ' /jkl/ { sub(/jkl/,doit) } {print}'
    asdf  asdf
    it doesnt work.

    at least i found that it is not a path related issue, since
    Code:
    echo asdf jkl asdf \
    | awk ' /jkl/ { sub(/jkl/,echo "("ENVIRON["PATH"]")") } {print}'
    asdf (/home/peter/bin:/opt/bin:/bin:/sbin:/usr/bin:/usr/sbin) asdf
    any ideas how i can make awk execute my ~/bin/doit ?
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    use the function 'system(), see man-pages..:'
    Code:
           system(cmd-line)      Execute  the command cmd-line, and return the exit status.  (This may not be available on non-POSIX
                                 systems.)

    Comment

    Working...