Search This Blog

Wednesday, October 29, 2008

TAB2XML awk script

This is a one level deep conversion from a tab file to xml.  So you have to manually change "catalog" and "sku" to your likings.
 
<code>
awk -F'\t' '
BEGIN { printf("<catalog>\n"); }
NR==1 {
for ( i=1 ; i<=NF ; i++ )
 name[i] = $i;
}
NR>1 {
 printf(" <sku>\n");
 for ( i=1 ; i<=NF ; i++ )
   printf("  <%s>%s</%s>\n",name[i],$i,name[i]);
   printf(" </sku>\n");
 }
END { printf("</catalog>\n"); }
' inventory.tab > inventory.xml

</code>
 

No comments: