Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any way to parse awk to just show me the host_name of a path?

Status
Not open for further replies.

DeyfishinDemhills

Technical User
Mar 26, 2012
1
US
I'm a NetApp admin for a board design firm here in California. I'm trying to automate the host_name location of all Role Accounts that exist in our network.

I use ypcat on our proprietary auto.home file to locate the Role Account individually and awk to print just the second "chunk" of resulting information,
Code:
#ypcat -k auto.home | grep -w ireland5 | awk '{print $2}'

the result always spits out the entire path where this Role Account is homed,
Code:
TCP-hombre02:/vol/vol01/Roleaccounts/&


What I really want is a result with JUST THE HOST_NAME, "TCP-hombre02" and nothing else. The path is important but I'm really interested in just the host.


Is awk really only limited to displaying a specific "chunk" as defined by value of x, as in {print $x]? If so, then how can I meet my goal of discovering a Role Account's host w/o the appending path?

Ideally, if I can figure this out I can automate discovery of thousands of RAs in our system and print this information to other maintenance applications in the enterprise.

many thanks,
FF#24
 
you could just add -> cut -d":" -f1 to the end of your line

Code:
#ypcat -k auto.home | grep -w ireland5 | awk '{print $2}'| cut -d":" -f1

or you can get into substr and index within the awk statement
 
If you change the field separators to be spaces and colons (add tabs too if necessary), you can do this:

Code:
#ypcat -k auto.home | awk -F'[ :]+' '/ireland5/{print $2}'

Also, as you can see, no need for grep when you're already running awk.

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top