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!

Help with parsing data 1

Status
Not open for further replies.

Kipnep70

Technical User
Nov 18, 2003
81
US
My data looks like the following:

Code:
id 34
name SERVERABC
port_count 2
type generic
mask 1111111111111111111111111111111111111111111111111111111111111111
iogrp_count 4
status online
site_id
site_name
host_cluster_id
host_cluster_name
WWPN 5001438002A3005A
node_logged_in_count 8
state active
WWPN 5001438002A30058
node_logged_in_count 8
state degraded
WWPN 5001438002A3005D
node_logged_in_count 8
state active
WWPN 5001438002A3005E
node_logged_in_count 8
state offline

I am passing it to awk and I am trying to get the following result:

Code:
Name              WWN                   State
SERVERABC         5001438002A3005A      active 
SERVERABC         5001438002A30058      degraded
SERVERABC         5001438002A3005D      active
SERVERABC         5001438002A3005E      offline

I have gotten this so far, but I don't know if I'm going in the right direction:

awk 'BEGIN{printf "%-32s %-32s %-12s\n", "name","wan","status"}/^name/{n=$2}/^WWPN/{w[$2]=w[$2]}END{for(i in w)printf "%-32s %-32s %-10s\n", n,i}'

any help appreciated. The input data is just one dataset, I will be piping in multiple datasets/inputs into awk to create the table. So there will be different Servers with different WWNs. Awk script needs to be able to handle variable number of WWNs.
 
Hi

Assuming the state will always occur after WWPN, the simplest would be to just record the last seen WWPN, then print them all when seeing a state :
Code:
[b]BEGIN[/b][teal]{[/teal][b]printf[/b] [i][green]"%-32s %-32s %-12s[/green][/i][lime]\n[/lime][i][green]"[/green][/i][teal],[/teal] [i][green]"name"[/green][/i][teal],[/teal][i][green]"wan"[/green][/i][teal],[/teal][i][green]"status"[/green][/i][teal]}[/teal][fuchsia]/^name/[/fuchsia][teal]{[/teal][navy]n[/navy][teal]=[/teal][navy]$2[/navy][teal]}[/teal][fuchsia]/^WWPN/[/fuchsia][teal]{[/teal][navy]w[/navy][teal]=[/teal][navy]$2[/navy][teal]}[/teal][fuchsia]/^state/[/fuchsia][teal]{[/teal][b]printf[/b] [i][green]"%-32s %-32s %-10s[/green][/i][lime]\n[/lime][i][green]"[/green][/i][teal],[/teal] n[teal],[/teal] w[teal],[/teal] [navy]$2[/navy][teal]}[/teal]


Feherke.
feherke.github.io
 
I guess I was trying to overcomplicate it by storing everything until the end. thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top