nawk -f Test.awk DCDB.xml LDS.xml input > input_new.txt
Jean-Pierre.
nawk -f Test.awk DCDB.xml LDS.xml input > input_new.txt
Jean-Pierre.
Not required this time
Not required this time
I don't understand your requirement.
Please post sample files (DCDB.xml, LDS.xml and inputfile) and required output.
Jean-Pierre.
Not required this time
> rm out.txt
> cat Malik.awk
#
# DCDB - This block select all DCBEntry records
# and memorize Folder and TZ.
# => Folder[dcdb] and Tz[dcdb]
#
/^[[:space:]]*<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
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
#
/^[[:space:]]*<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
ldsv = lds[6]; # Get LDSValue
SiteUnit[folder, ldsv] = lds[3]; # Memorize siteunit for folder,LDSValue
Device[folder, ldsv] = lds[4]; # Memorize device for folder,LDSValue
next; # Proceed next input record
} #
#
# Input - These blocks proceed inputfiles
#
/^[[:space:]]*</ || NF==0 { # Select (and ignore) records from DCDB and LDS and empty records
# (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
} #
$2 == "TOTAL" { # Select TOTAL record
print; # Print TOTAL record
next; # Proceed next input record
}
{ # Select all reamaining inputfile records
dcdb_in = $2; # Get dcdb from input record
if (length(dcdb_in) > 7) { # Check if dcdb and LDSValue merged
ldsv = substr(dcdb_in,8); # extract dcdb
dcdb_in = substr(dcdb_in,1,7);# extract LDSValue
} else # not merged
ldsv = $3; # Get LDSValue from input record
folder = Folder[dcdb_in]; # Get memorized folder for this dcdb
su = SiteUnit[folder, ldsv]; # Get memorized siteunit for this forder,ldsv
dev = Device[folder, ldsv]; # Get memorized device for this forder,ldsv
print $0, (folder ? folder : "?"), (su ? su : "?"), (dev ? dev : "?"); # Print record,
# folder, siteunit and device (unknown values are
# replaced by ?
next; # Proceed next input record
}
> cat Malik.sh
awk -f Malik.awk \
DCDB.xml \
LDS-*.xml \
LIVE9091.S20080817.txt \
> out.txt
> Malik.sh
> diff -b out.txt LIVE9091.S20080817_new.txt
>
Jean-Pierre.
I really thaks for your awk programming support.
Once again Thanks a lot , Now it is working fine.
Thanks & Regards
Sandeep Malik
Not required this time
Not required this time
The last version of my awk script accept leading spaces in DCDB and LDS records. I ran without anyproblem the script with your input files which contains leading spaces.
> head 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="0843365 " 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"/>
> Malik.sh
> head out.txt
DATE HHIDLDS BothOff 91 NG A=D 90faulRoundOnOff OffOn OthersMATCHED NOMATCH MATCH%RATE2% Folder SU Dev
0817 0201136 1 787 . . . . . . . 653 . 100.0 100.0 5912602 1 TV
0817 0201347 1 1290 . . . . . . . 150 . 100.0 100.0 5061234 1 TV
0817 0201347 2 533 . . . . . . . 907 . 100.0 100.0 5061234 2 TV
0817 0201364 1 866 . . . . . . . 574 . 100.0 100.0 5529737 1 TV
0817 0201364 2 1440 . . . . . . . . . . . 5529737 1 VCR1
0817 0201364 6 1323 . . . . . . . 117 . 100.0 100.0 5529737 4 TV
0817 0201364 7 1440 . . . . . . . . . . . 5529737 3 TV
0817 0201410 1 1157 . . . . . . . 283 . 100.0 100.0 5217848 1 TV
0817 0201410 3 1440 . . . . . . . . . . . 5217848 2 TV
>
Jean-Pierre.
Maybe below perl script can help you some.
open FH1,"<home";
while(<FH1>){
@arr=split(" ",$_);
$home{$arr[1]}="";
}
close(FH1);
open FH2,"<folder";
while(<FH2>){
@arr=split("\"",$_);
$arr[1]=~tr/ //d;
if (exists($home{$arr[1]})){
$home{$arr[1]}=$arr[3];
}
}
close(FH2);
open FH3,"<full";
while(<FH3>){
@arr=split("\"",$_);
@temp=split(":",$arr[1]);
for $key (keys %home){
if($temp[0] eq $home{$key}){
$home{$key}=sprintf("%s %s %s",$temp[0],$temp[1],$temp[2]);
}
}
}
close(FH3);
open FH1,"<home";
while(<FH1>){
@arr=split(" ",$_);
$_=~tr/\n//d;
if(exists($home{$arr[1]})){
print $_," ",$home{$arr[1]},"\n";
}
else{
print $_,"\n";
}
}
Not required this time
Try to replace [[:space:]] by [ \t]
Jean-Pierre.
Hi Jean,
Thanks a lot for prompt reply, now awk script is working fine with space also.
Thanks & Regards
Sandeep Malik
Not required this time
echo Enter DCDB path:
read DCDB
echo Enter LDS file path:
read LDS
echo Enter Input file path:
read Input
Output=./`basename $Input`_new.txt
nawk -f malik.awk $DCDB $LDS $Input > $Output
With your inputs, the file output file name will be : ./LIVE9091.S20080817_new.txt
Jean-Pierre.
Not required this time