Path: utzoo!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!casbah.acns.nwu.edu!ucsd!nosc!humu!pilikia!art From: art@pilikia.pegasus.com (Art Neilson) Newsgroups: comp.unix.programmer Subject: Re: Awk Message-ID: <1991Mar08.182518.22883@pilikia.pegasus.com> Date: 8 Mar 91 18:25:18 GMT References: <1991Mar7.115420.21315@daimi.aau.dk> <31137@shamash.cdc.com> Organization: Pilikia, Honolulu Lines: 44 In article <31137@shamash.cdc.com> mek@michael.udev.cdc.com (Mark Kennedy) writes: >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 >}' Since the original poster did ask about nawk as well, here's the solution to his problem in nawk: #! /usr/bin/nawk -f BEGIN { "/bin/date" | getline d print d exit } -- Arthur W. Neilson III | INET: art@pilikia.pegasus.com Bank of Hawaii Tech Support | UUCP: uunet!ucsd!nosc!pilikia!art