Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Help with parsing data

Help with parsing data

Help with parsing data

My data looks like the following:


id 34
port_count 2
type generic
mask 1111111111111111111111111111111111111111111111111111111111111111
iogrp_count 4
status online
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:


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.

RE: Help with parsing data


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 :


BEGIN{printf "%-32s %-32s %-12s\n", "name","wan","status"}/^name/{n=$2}/^WWPN/{w=$2}/^state/{printf "%-32s %-32s %-10s\n", n, w, $2} 


RE: Help with parsing data

I guess I was trying to overcomplicate it by storing everything until the end. thank you.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close