The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 08-25-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,423
A possible solution (try and adapt) :
Code:
awk '

#
# DCDB
#

/^<DCDBEntry / {
   split($0, dcdb, /"/);
   sub(/ *$/, "", dcdb[2]);
   Folder[dcdb[2]] = dcdb[4];
       Tz[dcdb[2]] = dcdb[6];
   next;
}

#
# LDS
#

/^<LDSEntry / {
   split($0, lds, /[":]/);
   folder = lds[2];
   tz     = lds[6];
   SiteUnit[folder, tz] = lds[3];
     Device[folder, tz] = lds[4];
   next;
}

#
# Input
#

/^</ {
   next;
}

FNR==1 {
   print $0, "Folder", "SU", "Dev";
   next;
}

{
   dcdb_in = $2;
   folder = Folder[dcdb_in];
   tz     =     Tz[dcdb_in];
   su     = SiteUnit[folder, tz];
   dev    =   Device[folder, tz];
   print $0, (folder ? folder : "?"), (su ? su : "?"), (dev ? dev : "?");
   next;
}

' DCDB.xml LDS-*.xml inputfile
DCDB.xml
Code:
> cat DCDB.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DCDBTable>
<DCDBEntry DCDB="0862976 " folder="768678" timeZone="2"/>
<DCDBEntry DCDB="0911297 " folder="975426" timeZone="1"/>
<DCDBEntry DCDB="0201347 " folder="1389781" timeZone="2"/>
<DCDBEntry DCDB="0800659 " folder="2035595" timeZone="4"/>
<DCDBEntry DCDB="0123033 " folder="2143699" timeZone="2"/>
<DCDBEntry DCDB="0911515 " folder="2315643" timeZone="1"/>
<DCDBEntry DCDB="0123913 " folder="2367867" timeZone="2"/>
<DCDBEntry DCDB="0713934 " folder="2407712" timeZone="5"/>
</DCDBTable>
LDS-*.xml
Code:
> cat LDS-*.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LDSMappingTable>
<LDSEntry LDSKey="3351216:1:TV" LDSValue="7"/>
<LDSEntry LDSKey="1389781:1:VCR1" LDSValue="2"/>
<LDSEntry LDSKey="3351216:2:TV" LDSValue="2"/>
<LDSEntry LDSKey="3351216:3:TV" LDSValue="6"/>
<LDSEntry LDSKey="3351511:1:TV" LDSValue="10"/>
<LDSEntry LDSKey="3351511:1:VCR1" LDSValue="11"/>
<LDSEntry LDSKey="3351511:2:TV" LDSValue="4"/>
<LDSEntry LDSKey="3351511:2:VCR1" LDSValue="5"/>
</LDSMappingTable>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LDSMappingTable>
<LDSEntry LDSKey="3351217:1:XTV" LDSValue="7"/>
<LDSEntry LDSKey="1389782:1:XVCR1" LDSValue="2"/>
<LDSEntry LDSKey="3351217:2:XTV" LDSValue="2"/>
<LDSEntry LDSKey="3351217:3:XTV" LDSValue="6"/>
<LDSEntry LDSKey="3351512:1:XTV" LDSValue="10"/>
<LDSEntry LDSKey="3351512:1:XVCR1" LDSValue="11"/>
<LDSEntry LDSKey="3351512:2:XTV" LDSValue="4"/>
<LDSEntry LDSKey="3351512:2:XVCR1" LDSValue="5"/>
</LDSMappingTable>
Inputfile
Code:
> cat inputfile
1DATE HHIDLDS BothOff 91 NG A=D 90faulRoundOnOff OffOn OthersMATCHED NOMATCH MATCH%
0721 0201136 1 544 . . . 1 . . . 895 1 99.89
0721 0201347 1 1296 . . . . . . . 144 . 100.0
0721 0201347 2 818 . . . . . . . 622 . 100.0
0721 0201364 1 1123 . . . . . . . 317 . 100.0
0721 0201364 2 1327 . . . . . . . 113 . 100.0
Output
Code:
1DATE HHIDLDS BothOff 91 NG A=D 90faulRoundOnOff OffOn OthersMATCHED NOMATCH MATCH% Folder SU Dev
0721 0201136 1 544 . . . 1 . . . 895 1 99.89 ? ? ?
0721 0201347 1 1296 . . . . . . . 144 . 100.0 1389781 1 VCR1
0721 0201347 2 818 . . . . . . . 622 . 100.0 1389781 1 VCR1
0721 0201364 1 1123 . . . . . . . 317 . 100.0 ? ? ?
0721 0201364 2 1327 . . . . . . . 113 . 100.0 ? ? ?
Jean-Pierre.