I pick up ip addresses from the access log, I want to find out where those IP addresses come from. To do this I use this script:

cat /var/log/nginx/access.log |awk '{ print $1}'|sort| uniq -c |sort -n -r | awk '{print $2}' 

an example output is:

I can pass the result to nslookup with the pipeline | command, but the result is not easy readable, so I tried to use the host command but the only output is an info how to use the host command.

How can I use host command to batch resolve ip addresses?

1 Answer 1


You can use xargs, it converts input from standard input into arguments to a command.

The option -n limits the arguments to one (delimited by newline), and call host multiple times for each one of them, so you can do:

cat /var/log/nginx/access.log |awk '{ print $1}'|sort| uniq -c |sort -n -r | awk '{print $2}' | xargs -n 1 host

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.