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 212469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:11:23+00:00 2026-05-11T18:11:23+00:00

I have a XML file with the following data format: <net NetName=abc attr1=123 attr2=234

  • 0

I have a XML file with the following data format:

<net NetName="abc" attr1="123" attr2="234" attr3="345".../>
<net NetName="cde" attr1="456" attr2="567" attr3="678".../>
....

Can anyone tell me how could I data mine the XML file using an awk one-liner? For example, I would like to know attr3 of abc. It will return 345 to me.

  • 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-05-11T18:11:23+00:00Added an answer on May 11, 2026 at 6:11 pm

    In general, you don’t. XML/HTML parsing is hard enough without trying to do it concisely, and while you may be able to hack together a solution that succeeds with a limited subset of XML, eventually it will break.

    Besides, there are many great languages with great XML parsers already written, so why not use one of them and make your life easier?

    I don’t know whether or not there’s an XML parser built for awk, but I’m afraid that if you want to parse XML with awk you’re going to get a lot of “hammers are for nails, screwdrivers are for screws” answers. I’m sure it can be done, but it’s probably going to be easier for you to write something quick in Perl that uses XML::Simple (my personal favorite) or some other XML parsing module.

    Just for completeness, I’d like to note that if your snippet is an example of the entire file, it is not valid XML. Valid XML should have start and end tags, like so:

    <netlist>
      <net NetName="abc" attr1="123" attr2="234" attr3="345".../>
      <net NetName="cde" attr1="456" attr2="567" attr3="678".../>
      ....
    </netlist>
    

    I’m sure invalid XML has its uses, but some XML parsers may whine about it, so unless you’re dead set on using an awk one-liner to try to half-ass “parse” your “XML,” you may want to consider making your XML valid.

    In response to your edits, I still won’t do it as a one-liner, but here’s a Perl script that you can use:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use XML::Simple;
    
    sub usage {
      die "Usage: $0 [NetName] ([attr])\n";
    }
    
    my $file = XMLin("file.xml", KeyAttr => { net => 'NetName' });
    
    usage() if @ARGV == 0;
    
    exists $file->{net}{$ARGV[0]}
      or die "$ARGV[0] does not exist.\n";
    
    
    if(@ARGV == 2) {
      exists $file->{net}{$ARGV[0]}{$ARGV[1]}
        or die "NetName $ARGV[0] does not have attribute $ARGV[1].\n";
      print "$file->{net}{$ARGV[0]}{$ARGV[1]}.\n";
    
    } elsif(@ARGV == 1) {
      print "$ARGV[0]:\n";
      print "  $_ = $file->{net}{$ARGV[0]}{$_}\n"
        for keys %{ $file->{net}{$ARGV[0]} };
    
    } else {
      usage();
    }
    

    Run this script from the command line with 1 or 2 arguments. The first argument is the 'NetName' you want to look up, and the second is the attribute you want to look up. If no attribute is given, it should just list all the attributes for that 'NetName'.

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

Sidebar

Ask A Question

Stats

  • Questions 134k
  • Answers 134k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If your "custom stream" isn't something you can represent with… May 12, 2026 at 6:48 am
  • Editorial Team
    Editorial Team added an answer It depends. If you need to property values to be… May 12, 2026 at 6:48 am
  • Editorial Team
    Editorial Team added an answer When undefined is cast to a string (which the regex… May 12, 2026 at 6:48 am

Related Questions

I have at least 100 xml files each about 300 MB with email messages
I would like to design a web app that allows me to sort, browse,
We are in evaluating technologies that we'll use to store data that we gather
I made a test file, and ran through the excel file just fine, but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.