Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a text file with a list ip addresses and other information.

I am using an awk script to process this list and output various computations. I want to call dig -x from inside the awk script and use the returned value.

I have tried

hostname = system("dig +short -x" ip_address);

but what occurs is -

  1. the call to dig prints a line to the shell

  2. hostname remains null

share|improve this question
up vote 9 down vote accepted

Figured it out, but please feel free to add better answers

cmd = "dig +short -x " ;
cmd ip_address | getline hostname;
close(cmd)

Then I can use the hostname anywhere in the script.

share|improve this answer
    
This is the correct way to do it. You will probably want to do close(cmd) afterwards. – Dennis Williamson Jan 7 '11 at 18:44
    
Yes thanks, found out about that after this posting, will close the question in 2 days(superuser requirement) – bryan Jan 7 '11 at 19:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .