DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Using awk

The system function

The built-in function system(command-line) executes the command command-line, which can be a string computed by, for example, the built-in function sprintf. The value returned by system is the return status of the command executed. The output from command-line is not automatically available for use within the awk script. It must be piped into getline, as follows:

system(command-line | getline)

The following program calls the shell command cat(C) to print the file named in the second field of every input record whose first field is ``#include,'' having first stripped any <, >, or " characters that might be present:

   $1 == "#include" { gsub(/[<>"]/, "", $2); system("cat " $2) }

Next topic: Cooperation with the shell
Previous topic: Using awk with other commands and the shell

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003