0

I'm collecting the VLAN details for each VIO server and LPAR's from HMC. I would need to group those VLANs one Vwsitch as VSWITCHName=VLANID, separated by comma. But some VIO servers have 2 VSWITCHES. I would like to display the data on single line as i'm using for loop to collect the data.

LAB1:~> lshwres -m system-01 -r virtualio --rsubtype eth --level lpar --filter lpar_names=ABC1234 -F vswitch:port_vlan_id:addl_vlan_ids ETHERNET0:64: ETHERNET0:2215:52,64 ETHERNET0:3969:701,702,2152,2154 ETHERNET0:4001: LAB1:~> lshwres -m system-01 -r virtualio --rsubtype eth --level lpar --filter lpar_names=ABCD4567 -F vswitch:port_vlan_id:addl_vlan_ids ETHERNET1:55: ETHERNET1:3971:51,53,55 ETHERNET1:3972:2151,2153,2155 ETHERNET1:4002: hmclab:~> lshwres -m system-01 -r virtualio --rsubtype eth --level lpar --filter lpar_names=ABCD7890 -F vswitch:port_vlan_id:addl_vlan_ids ETHERNET0:52: ETHERNET0:2152: LAB1:~> lshwres -m system-01 -r virtualio --rsubtype eth --level lpar --filter lpar_names=ABCD7869 -F vswitch:port_vlan_id:addl_vlan_ids ETHERNET0:54:4001 ETHERNET0:3968:52,54 ETHERNET1:3969:701,702,2152,2154,5569 ETHERNET1:4002: ETHERNET1:5001 

Output Expected is: ETHERNET0= 52,54,3968,etc & ETHERNET1=5001,3969.701,etc

3
  • @Kusalananda - Need your inputs Commented Apr 26, 2018 at 9:16
  • I'd like to help but I don't understand the aix context. Could you complete your expected output, replacing the etc? Are you providing 4 separate examples, or are they supposed to be combined into one? Commented Apr 26, 2018 at 10:18
  • @meuh, Sorry if i confused you, I would like to group ETHERNET0 and ETHERNET1 VLAN's on same line Commented Apr 26, 2018 at 17:34

1 Answer 1

0

If you want to join up the lines with the same ethernet number, and replace the : by a , then you can pipe the output into

awk -F: ' /ETHERNET/{ i = $1; v[i] = v[i] "," $2; if($3!="")v[i] = v[i] "," $3 } END{ n = asorti(v,x) for(j=1;j<=n;j++){ i = x[j]; print i "=" substr(v[i],2) } }' 

This splits each line on :, uses the first field ETHERNET0 as an index into an associative array v, which collects fields 2 and 3 (if field 3 isn't empty). At the end of input, the keys (indices) of the array are sorted so we can start output with ETHERNET0, and for each key we print it and the collected fields, omitting the first character which is always an extra comma, since we always add it before field 2.

The result, treating each of your commands as independent, is:

ETHERNET0=64,2215,52,64,3969,701,702,2152,2154,4001 ETHERNET1=55,3971,51,53,55,3972,2151,2153,2155,4002 ETHERNET0=52,2152 ETHERNET0=54,4001,3968,52,54 ETHERNET1=3969,701,702,2152,2154,5569,4002,5001 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.