Weet u zeker dat alle gegevens die beginnen met '<' in de dossiers DCDB.xml en LDS.xml?
Ik heb het getest becommentarieerde awk script zonder probleem:
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>
> cat LDS-1.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>
> cat LDS-2.xml
<?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>
> 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
> cat Malik.awk
#
# DCDB - This block select all DCBEntry records
# and memorize Folder and TZ.
# => Folder[dcdb] and Tz[dcdb]
#
/^<DCDBEntry / { # Select DCDBEntry records
split($0, dcdb, /"/); # Split record into dcdb array (sep=")
# dcdb[2]=dcdb, dcdb[4]=folder,
# dcdb[6]=tz
sub(/ *$/, "", dcdb[2]); # Remove trailing spaces from dcdb
Folder[dcdb[2]] = dcdb[4]; # Memorize folder for dcdb
Tz[dcdb[2]] = dcdb[6]; # Memorize tz for dcdb
next; # Proceed next input record
} #
#
# LDS - This block select all LDSEntry records
# and memorize SiteUnit and Devide for folder,tz
# => SiteUnit[folder,tz] and Devicefolder,tz
#
/^<LDSEntry / { # Select LDSEntry records
split($0, lds, /[":]/); # Split record into lds array (sep=" or sep=:)
# lds[2]=folder, lds[3]=siteunit
# lds[4]=device, lds[6]=tz
folder = lds[2]; # Get folder
tz = lds[6]; # Get tz
SiteUnit[folder, tz] = lds[3]; # Memorize siteunit for folder,tz
Device[folder, tz] = lds[4]; # Memorize device for folder,tz
next; # Proceed next input record
} #
#
# Input - These blocks proceed inputfiles
#
/^</ { # Select (and ignore) records from DCDB and LDS
# (DCDBEntry ans LDSEntry have already been processed)
next; # Procced next input record
} #
FNR==1 { # Select first record of inputfile (logically all other files
# have been processed in previus blocks).
print $0, "Folder", "SU", "Dev"; # Print first record (headers) and add new headers
next; # Proceed next input record
} #
{ # Select all reamaining inputfile records
dcdb_in = $2; # Get dcdb from input record
folder = Folder[dcdb_in]; # Get memorized folder for this dcdb
tz = Tz[dcdb_in]; # Get memorized tz for this dcdb
su = SiteUnit[folder, tz]; # Get memorized siteunit for this forder,tz
dev = Device[folder, tz]; # Get memorized device for this forder,tz
print $0, (folder ? folder : "?"), (su ? su : "?"), (dev ? dev : "?"); # Print record,
# folder, siteunit and device (unknown values are
# replaced by ?
next; # Proceed next input record
}
> awk -f Malik.awk DCDB.xml LDS-1.xml LDS-2.xml inputfile
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 ? ? ?
>