-   Linux - Newbie (
-   -   Combine two awk expressions (

shivaa 11-09-2012 05:57 AM

Combine two awk expressions
Hello friends, I am a beginnner in awk, so need little help! I am trying to get hostnames against IP, and I did:

example# nslookup
Server: ....
Address: .....


Now I want only hostname as output, so I did:

example# nslookup | awk '/Name/' | awk -F" " '{print $2}'
So my question is, how to combine these two awk expression to form a single awk command. How we can combine multiple awk expressions in a single cmd? I tried seaching many articles, but couldn't get anything helpful. I am expecting not just full command, but also a well explained answer.
Thanks in advance!

pan64 11-09-2012 06:03 AM

this kind of expressions can be combined easily:
awk ' /pattern/ { print $2 } '
should work
otherwise it depends on the two expressions

shivaa 12-07-2012 12:58 PM

Solved with:

nslookup <ip> | awk '/Name/ {print $2}'

All times are GMT -5. The time now is 05:23 PM.