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

  • Home
  • SEARCH
  • 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 7990805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:07:06+00:00 2026-06-04T13:07:06+00:00

I am looking for a solution to this problem and suspect awk should provide

  • 0

I am looking for a solution to this problem and suspect awk should provide a simple enough solution instead of my clumsy shell script.

I have an xml file consisting of multiple sections as shown below. I also have a list of values.

For each section <top_tag> ... </top_tag> where value_x is in my list, delete (ie:not print) the section <top_tag> ... </top_tag>

<xml>
<outer_tag>
   <top_tag>
      <tag>value_1</tag>
      <other_tags></other_tags>
   </top_tag>
   <top_tag>
      <tag>value_2</tag>
      <other_tags></other_tags>
   </top_tag>
    ...
   <top_tag>
      <tag>value_n</tag>
      <other_tags></other_tags>
   </top_tag>
</outer_tag>

Your suggestions are most 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-04T13:07:07+00:00Added an answer on June 4, 2026 at 1:07 pm

    What you need here is not awk but XSLT, which was created specifically for this kind of tasks. It lets you transform an xml document into a different xml.

    For an input much like yours:

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="example.xsl"?>
    <outer_tag>
       <top_tag>
          <tag>value_1</tag>
          <other_tags></other_tags>
       </top_tag>
       <top_tag>
          <tag>value_2</tag>
          <other_tags></other_tags>
       </top_tag>
       <top_tag>
          <tag>value_3</tag>
          <other_tags></other_tags>
       </top_tag>
       <top_tag>
          <tag>value_n</tag>
          <other_tags></other_tags>
       </top_tag>
    </outer_tag>
    

    The following XSLT removes all top_tag elements with value_3 by simply not copying them and ignoring their contents.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="*">
            <xsl:element name="{name()}">           
                <xsl:apply-templates select="child::node()"></xsl:apply-templates>
            </xsl:element>
        </xsl:template>
    
        <xsl:template match="top_tag[tag = 'value_3']">     
        </xsl:template>
    </xsl:stylesheet
    

    Every major programming language has at least a couple of libraries that can process an XML input according to an XSLT. Command line tools and UI-based applications (IDEs but not only those) can do it as well. Finally, web browsers can transform files using XSLT if you include the xsl file with a processing instruction like this:

    <?xml-stylesheet type="text/xsl" href="example.xsl"?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Figure there is a simple solution to this problem but I have been unable
I have been looking for a solution to this problem for ages. I have
I have been looking around for a solution for this problem that works across
I have been looking for a little while for a solution to this problem,
I'm looking for a nice tight regex solution to this problem. I'm looking to
I am looking for a general and complete solution to this common problem! I
I'm looking for a solution to this problem. I got 2 arrays, like this:
hey I'm looking for are clean solution to this problem: i start the loop
We are looking into a solution for this problem: We host a ASP.NET web
I have searched this site, and numerous others, looking for a solution to this

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.