Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8151413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:22:53+00:00 2026-06-06T15:22:53+00:00

I have a bunch of xml files named content_[0-9] (content underscore followed by a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:22:54+00:00Added an answer on June 6, 2026 at 3:22 pm

    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:

    foreach ($i in get-childitem $loc -recurse){
        if ($i.name -match "content_"){
            $content = get-content $i.FullName
            $airportcode=get-content $i.FullName | select-string -pattern "<airport_code>"
            $airportcode= $airportcode -replace "<airport_code>", "" 
            $airportcode= $airportcode -replace "</airport_code>", ""
            $airportcode= $airportcode -replace "  ", ""
            $timezone=$timezones.Get_Item("$airportcode")
            $newContent = $content -replace "</airports>", ""
            $newContent = $newContent -replace "  ","`n  "
            $newContent="$($newContent)`n<timezone>$($timezone)</timezone>`n</airports>"
            Set-Content $i.FullName $newContent
        } 
    }
    

    note that this also removes the closing element tag </airports> and then appends it to the document at the end.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge bunch of XML files with the following structure: <Stuff1> <Content>someContent</name>
I have a bunch of XML files I'm using for user interface and string
I have a bunch of XML files that are about 1-2 megabytes in size.
I need to parse a bunch of incoming xml documents, they all have the
I have a bunch of xml files with a varying amount of data nodes
I have a bunch of .xml files with nodes that are causing uncessesary complications.
I have a bunch of .properties file and .xml files. Can I comment/uncomment some
I have a bunch of XML files which are using prefixes but without the
I have two XML files. The first XML has a bunch of nodes that
I have a bunch of XML Files which I have parsed into discrete fields.I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.