shell commands within awk script 
Author Message
 shell commands within awk script

How can I execute a shell command withing an awk script?


Sun, 29 Sep 2002 03:00:00 GMT  
 shell commands within awk script

Quote:

>How can I execute a shell command withing an awk script?

use awk's system function.

man awk
man nawk
man gawk

Here's an example (including some fancy quoting to maintain spaces):

#!/bin/sh
echo "a" > tmp
ls -l tmp
echo "a" | awk '{cmd="ls > tmp" ; string = "Hello  World!";
                 system("echo \"" string "\""); system(cmd)}'
ls -l tmp
# end of script

that script, executed in my home directory produces this output:

-rw-------    1 cpd      cpd            2 Apr 12 19:41 tmp
Hello  World!
-rw-------    1 cpd      cpd          560 Apr 12 19:41 tmp

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Sun, 29 Sep 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. trying to call awk from within a shell script

2. Shell variable within an awk script

3. Invoking shell command from within awk

4. executing a shell command within AWK

5. Problem with get exit status of shell script/command within expect

6. Shell commands from within a script

7. Passing command line variables to AWK in shell script

8. Simple awk command within a perl script

9. Access to Script Name Within Awk Script

10. Starting interactive shell/irb from within a script?

11. calling shell editor within script

12. EXPECT : calling shell fns. from within expect script

 

 
Powered by phpBB® Forum Software