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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:37:34+00:00 2026-05-22T18:37:34+00:00

I need to read some filenames from an xml config file using xmlstarlet with

  • 0

I need to read some filenames from an xml config file using xmlstarlet with an .sh script and merge contents of these files (in same order) into a single file.

Here is my xml structure:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <level1>
      ...
    </level1>

    <level2>
        <david>
            <txtfile>file1.txt</txtfile>
            <txtfile>file2.txt</txtfile>
            <txtfile>somefile.txt</txtfile>

            <incfile>config.inc</incfile>
            <incfile>foo.inc</incfile>
       </david>
       <jack>
           <txtfile>filex.txt</txtfile>
           <txtfile>filey.txt</txtfile>

           <incfile>otherconfig.inc</incfile>
           <incfile>foo1.inc</incfile>
       </jack>
    </level2>
</config>

After reading (maybe adding to an array in bash) these filenames using xmlstarlet i have to merge file contents into a single file using a command like

cat file1.txt,file2.txt,filex.txt > jack.txt

but i’m not sure. I don’t have good skills in .sh scripting but in summary, i need to generate some merged files which including contents of above filenames like this:

/level2/david.txt (includes file1.txt, file2.txt, somefile.txt )
/level2/david.inc (includes config.inc, foo.inc)
/level2/jack.txt  (includes filex.txt, filey.txt)
/level2/jack.inc  (includes otherconfig.inc, foo1.inc)

How can i do that?

  • 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-22T18:37:35+00:00Added an answer on May 22, 2026 at 6:37 pm
    xmlstarlet el /tmp/x.xml | sort -u | while read f; do E=""; case "$f" in */txtfile) E=".txt";; */incfile) E=".inc";; *) continue; esac; ONE=`dirname $f`; TWO=`dirname $ONE`; ONE=`basename $ONE`; TWO=`basename $TWO`; filename="/$TWO/$ONE$E"; echo "cat `xmlstarlet sel -t -c \"$f\" /tmp/x.xml |  sed -e 's|</[^>]*><[^>]*>| |g' -e 's|<[^>]*>||g'` >> $filename"; done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to read some large files (from 50k to 100k lines), structured in
I need to read from a variety of different text files (I've some delimited
I need to read selected files, matching on the file name, from a remote
I need to read the value of a property from a file in an
I've an XML file stored in App_Data which is only used to read some
I need to import some data from a excel file and a folder with
I read some articles on net for sending the files using HTTP/(Ajax). While reading
I need to import a binary file from Python -- the contents are signed
I need some help ... I'm a bit (read total) n00b when it comes
I read the SDK document, but can not understand some details, need some help.

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.