Xref: utzoo comp.unix.programmer:1242 comp.unix.misc:1074 Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!uwm.edu!src.honeywell.com!msi.umn.edu!noc.MR.NET!uc!shamash!michael.udev.cdc.com!mek From: mek@michael.udev.cdc.com (Mark Kennedy) Newsgroups: comp.unix.programmer,comp.unix.misc Subject: Re: Awk Message-ID: <31137@shamash.cdc.com> Date: 7 Mar 91 19:32:11 GMT References: <1991Mar7.115420.21315@daimi.aau.dk> Sender: usenet@shamash.cdc.com Reply-To: mek@michael.udev.cdc.com (Mark Kennedy) Followup-To: comp.unix.programmer Organization: Control Data Corporation Lines: 44 In article <1991Mar7.115420.21315@daimi.aau.dk>, ezra@daimi.aau.dk (Thomas Ravnholt) writes: |> Hello ! |> |> I have a little question about awk (nawk). |> |> 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 }' You can use the pid if you are worried about stepping on duplicate temp file names and insert a "trap" command to delete your temp file(s) in case your script terminates prematurely. -Mark -- ___ ___ / __||__ \ Mark Kennedy ( |__ __| ) AT&T: (612) 482-2787 Control Data Corporation \___||___/ E-Mail: mek@udev.cdc.com check-ins happen