Awk s system() function passes the string to /bin/sh, so you can use redirect operators, like ">file.out" if you want.
awk {system("command " $1 " " $2 " " $3 ">" $1 ".out");}
Edit: ok, by save, you mean into an awk variable. ephemient is on the right track, then. That s what awk s getline does, like backticks or $(cmd) in shell/perl. In fact, google for awk backticks found this:
http://www.omnigroup.com/mailman/archive/macosx-admin/2006-May/054665.html
You say you can t use getline because then you couldn t pipe. But you can work around that with tee and file-descriptor tricks. This works if /bin/sh is bash:
{ "set +o posix; command " $1 " " $2 " " $3 " | tee >(grep foo)" | getline var; print toupper(var); } # bash-only, and broken.
set +o posix
is necessary because awk runs bash as sh
, which makes it go into posix mode after readings its startup files. Hmm, I m not having any luck getting that to work, and it requires bash anyway.
Ok, this works:
$ touch foo bar
$ echo "foo bar" |
awk { "{ ls " $1 " " $2 " " $3 " | tee /dev/fd/10 | grep foo > /dev/tty; } 10>&1" | getline var; print toupper(var); }
foo
BAR