LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Combine two awk expressions (http://www.linuxquestions.org/questions/linux-newbie-8/combine-two-awk-expressions-4175436386/)

shivaa 11-09-2012 04: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:
Code:

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

Name: hostname.domain.org.com
Address:....

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

example# nslookup 10.123.10.20 | 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 05: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 11:58 AM

Solved with:
Code:

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


All times are GMT -5. The time now is 01:22 PM.