LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-09-2012, 04:57 AM   #1
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
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!

Last edited by shivaa; 11-09-2012 at 05:03 AM.
 
Old 11-09-2012, 05:03 AM   #2
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,466

Rep: Reputation: 1213Reputation: 1213Reputation: 1213Reputation: 1213Reputation: 1213Reputation: 1213Reputation: 1213Reputation: 1213Reputation: 1213
this kind of expressions can be combined easily:
awk ' /pattern/ { print $2 } '
should work
otherwise it depends on the two expressions
 
1 members found this post helpful.
Old 12-07-2012, 11:58 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
Solved with:
Code:
nslookup <ip> | awk '/Name/ {print $2}'
 
  


Reply

Tags
awk


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Can I come combine the panels in 10.10? Advice Pro Ubuntu 10 01-27-2012 08:18 PM
Combine two LVM newFreeBSD Linux - Server 1 04-18-2011 03:04 AM
[SOLVED] Combine pdf? dili Linux - Software 1 06-19-2010 10:18 AM
Possible to combine kernels? JimBass Linux - Newbie 1 10-06-2004 05:52 PM
Best way to combine files? JockVSJock Programming 4 04-25-2004 07:38 PM


All times are GMT -5. The time now is 04:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration