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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:24:11+00:00 2026-05-20T01:24:11+00:00

Here is the xml snippet: $ cat short.xml <hostnames> <hostname name=yahoo.com type=user/> <hostname name=ir1.fp.vip.sp2.yahoo.com

  • 0

Here is the xml snippet:

$ cat short.xml 
<hostnames>
    <hostname name="yahoo.com" type="user"/>
    <hostname name="ir1.fp.vip.sp2.yahoo.com" type="PTR"/>
</hostnames>
<hostnames>
    <hostname name="Inc.com" type="user"/>
    <hostname name="www.inc.com" type="PTR"/>
</hostnames>

The desired output is:

yahoo.com | ir1.fp.vip.sp2.yahoo.com
Inc.com | www.inc.com

What I have so far that is only partially working:
$ xml sel -t -m “//hostname” -v “@name” -n short.xml

I cannot seem to trap the Type= condition properly. TIA.

  • 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-20T01:24:11+00:00Added an answer on May 20, 2026 at 1:24 am

    You need to count the hostnames with xmlstarlet el or something and then iterate with something like:

    xmlstarlet sel -t -c "//hostnames[1]" short.xml | xmlstarlet sel -t -m "//hostname/@name" -v . -o ' | '
    

    This would be a lot easier if the XML was better designed. 🙂

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

Sidebar

Related Questions

In an XML file such as : <Snippets> <Snippet name=abc> <SnippetCode> code goes here
here is the XML file : <com.google.android.maps.MapView android:layout_width=fill_parent android:layout_height=fill_parent android:apiKey=0q7NUYm4bgzeXlqXtKYVPJDRWUJmt8Cu0gvbWMx android:id=@+id/map_view /> and Manifest
I'm parsing flight times in my iPhone app. Here's a snippet from the XML
Here's an XML snippet: <appSettings> <add key=val1 value=val2/> The XML document is loaded in
Here is a snippet from the XML file I am trying to parse: <Item
Here is a snippet of the XML file I am trying to read. <?xml
Here is a snippet of the XML file: <Catalog> <CDs> <CD> <Manuals> <Manual>123DHX<Manual> <Manual>5axDHX<Manual>
Here's the code snippet: XDocument themes = XDocument.Load(HttpContext.Current.Server.MapPath(~/Models/Themes.xml)); string result = ; var childType
The application I work uses XML for save/restore purposes. Here's an example snippet: <?xml
With glassfish, my persistence.xml is not loaded. my.ear META-INF/persistence.xml lib/entities.jar <!-- no persistence.xml here

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.