help needed to get the output from file

Hi All,

i have a file with below contents (single line) pasted below

[

 
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.grid-pnp.org/2005/11/gpnp-profile gpnp-profile.xsd" ProfileSequence="4" ClusterUId="a412e044b1986f00bfb208e0b89d90bf" ClusterName="lab1-cluster" PALocation=""><gpnp:Network-Profile><gpnp:HostNetwork id="gen" HostName="*"><gpnp:Network id="net1" IP="10.26.208.0" Adapter="en0" Use="public"/><gpnp:Network id="net2" IP="192.168.3.0" Adapter="en1" Use="cluster_interconnect"/><gpnp:Network id="net3" IP="192.168.4.0" Adapter="en2" Use="cluster_interconnect"/></gpnp:HostNetwork></gpnp:Network-Profile><orcl:CSS-Profile id="css" DiscoveryString="+asm" LeaseDuration="400"/><orcl:ASM-Profile id="asm" DiscoveryString="/dev/asmdisk/*" SPFile="+GRID/lab1-cluster/asmparameterfile/registry.253.790951985"/><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI=""><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"> <InclusiveNamespaces xmlns="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="gpnp orcl xsi"/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>gUWgCm2nA6j9KyTDnM0DHOPy5jw=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>okgwkk8HwHtEIoa708Wdz1d+4P4Q75g3e6bfZr/w0jIOf6yT6dzGquNlZUE/iDvbcdj0LFDRgP2pIr/U+tK2SXw4MicSeSIKWrP8BDn8pCZv7BIzaUW+B6BlqM5HjY34d9/cI0+hDAn5bju1opS2XsTUY3wKmwgP4Jo2v0YMNMo=</ds:SignatureValue></ds:Signature></gpnp:GPnP-Profile>

](http://www.w3.org/2001/XMLSchema-instance)

Whenever Use="Public" need to get the Adaptar=en0 then Use=cluster_interconnect need to get the Adaptar=en1 & en2
Output needed like below

 Public Adaptar = en0
 Private1 Adaptar = en1
 Private2 Adaptar = en2

Regards
Kannan

This will do the job for your example:

awk    'BEGIN {RS="/"; FS="[= \"]+"}
     /Adapter/ {
            for (i=NF;i>=1;i--) if ($i=="Adapter") break;
            sub("cluster_interconnect","Private"ct++,$(i+3))
            print $(i+3), "Adapter =", $(i+1)
           }
    ' infile
public Adapter = en0
Private1 Adapter = en1
Private2 Adapter = en2
1 Like

Thanks a lot !!!! working perfectly

To protect it from changes in the order the adapters occur, try this version:

awk    'BEGIN {RS="/"; FS="[= \"]+"}
     /cluster_interconnect/ {sub("cluster_interconnect","Private"++ct)}
     /Adapter/ {
            for (i=NF;i>=1;i--) if ($i=="Adapter") break;
            print $(i+3), "Adapter =", $(i+1)
           }
    ' infile
1 Like