Awk
Heiko Schlichting
heiko at methan.chemie.fu-berlin.de
Fri Mar 8 10:41:55 AEST 1991
mek at michael.udev.cdc.com (Mark Kennedy) writes:
>ezra at daimi.aau.dk (Thomas Ravnholt) writes:
>> If I want to run a unix-command in an awk-script,
>> how do I get the output into a variable.
>>
>> I tried
>> getline < system(unixcommand)
>> system(unixcommand | getline)
>>
>> but it is no good of course. system returns 0 or 1 and
>> not the output of the unixcommand.
>Crude, but effective, temporary files are your friend. Here's a
>simple example that does what you ask.
>
>#! /bin/sh
>
>awk '
>BEGIN {
>system("date > /tmp/foo")
>getline X < "/tmp/foo"
>print X
>}'
Using GNU-awk 2.11.1 it is easier with:
awk 'BEGIN{ "date"|getline X; close("date"); print X}' /dev/null
Bye, Heiko.
--
|~| Heiko Schlichting | Freie Universitaet Berlin
/ \ heiko at fub.uucp | Institut fuer Organische Chemie
/FUB\ heiko at methan.chemie.fu-berlin.de | Takustrasse 3
`---' phone +49 30 838-2677; fax ...-5163 | D-1000 Berlin 33 Germany
More information about the Comp.unix.programmer
mailing list