I have a bunch of xml files named content_[0-9] (content underscore followed by a single digit) in a bunch of seperate directories. These files all have a single airport_code element like so:
<airport_code>JFK</airport_code>
I then have a key value mappings like so:
JFK=US/Eastern
LHR=Europe/London
etc
I want to cycle through all these xml files and append the correct timezone element to each xml file, so that the JFK file would read:
<airport_code>JFK</airport_code>
<timezone>US/Eastern</timezone>
Im trying to do this in a windows batch script (with unix utils installed). Here’s what I have so far:
@echo off
for /d %%x in (C:\directory\*) do type %%x\content_? | grep "<airport_code>" | gawk "{gsub(/ <airport_code>/, \"\"); print}" | gawk "{gsub(/<\/airport_code>/, \"\"); print}"
Which will read the airport codes of all the xml files out.
How would I look upp the value in my key-value pair for each airport code and append the appropriate timezone element? Is this possible? Any help greatly appreciated.
I managed to resolve this on my own, but only by switching over to the powershell. Comments and improvements are appreciated, as are suggestions for doing things within cmd:
note that this also removes the closing element tag </airports> and then appends it to the document at the end.