Purpose is to generate XML file based on flat file , using awk. I managed to do it by pure coding. (print " .. etc . But I want a more awk-way by using printf fmt .
Input file (there are more similar lines) - I did not mention header lines (title : map entries mem) .
Mapone 5 10
Maptwo 12 45
Maptree 8 7
Result file should be like :
<Map>Mapone</Map>
<entries>5</entries>
<mem>10</mem>
<Map>Maptwo</Map>
<entries>12</entries>
<mem>45</mem>
<Map>Maptree</Map>
<entries>8</entries>
<mem>7</mem>
Currently i use
BEGIN {FS=" " ;
print "<?xml version=\"1.0\"?>";
}
{ Map = $1; }
{ Entry = $2;}
{ mem = $4;}
{
fmt = fmt "\t<Mapname>%s</Mapname>\n";
fmt = fmt "\t\t<Entries>%s</Entries>\n";
fmt = fmt "\t\t<Mem>%s</Mem>\n";
printf fmt, Map, Entry, mem ;
}
===> this script result in error containing "awk: There are not enough parameters in printf statement"
printfstatement should be something likeprintf "%s %s %s %s", fmt, Map, Entry, mem ;. You are missing that.fmtas the format so don't require the first bit in your exampleprintfwith all the placeholders.