Parsing XML (and insert data) then output data (bash / Solaris)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing XML (and insert data) then output data (bash / Solaris)
# 1  
Old 03-27-2013
Parsing XML (and insert data) then output data (bash / Solaris)

Hi folks

I have a script I wrote that basically parses a bunch of config and xml files works out were to add in the new content then spits out the data into a new file.

It all works - apart from the xml and config file format in the new file

with XML files the original XML (that ends up in the destination file)
Code:
<no action="setACL" send="Y">
<ACL node="" name="" value="" />
<ACL node="" name="" value="01" />
</no>

but it should look like this (this is the new stuff I am inserting)
Code:
    <bit bitpos="" action="setACL" no="Y">
      <ACL node="" name="" value="Default" />
      <ACL node="" name="" value="00" />
    </bit>

on config files - which are just standard flat files,the original file looks like this:
Code:
# -------------------------------------------------
# LB Health Check
# -------------------------------------------------
User-Name Equals LB accountwrite=n

but I get this:
Code:
 # -------------------------------------------------
 # LB Health Check
 # -------------------------------------------------
 User-Name Equals LB accountwrite=n

I use the same function for each file - the content is spot on I just cannot see how to get the xml formatting correct (the non-xml files I can live with) and looks like this :
Code:
      tFile=/tmp/newtest.tmp
        if [ -e ${dFile} ]; then rm -rf ${dFile}; fi
        while read line
        do
                let cnt=cnt+1;
                if [ ${cnt} -eq ${insertAtLine} ]; then
                        echo -e "${insertThis}" >> ${dFile}
                echo -e "**** Inserted OK! ****"
                else
                        echo -e ${line} >> ${dFile}
                fi
        done < ${sFile}
        cnt=0

$insertThis is the text I need to insert
$insertAtLine is the line I need to insert the text at
$dFile = destination file
$tFile = temporary file

so, basically
Code:
                      echo -e "${insertThis}" >> ${dFile}

works, and
Code:
                        echo -e ${line} >> ${dFile}

this is whats giving me grief!

This is driving me crazy btw,
# 2  
Old 03-28-2013
To clarify - what you have an issue with is the whitespace/indentation in the output, not the actual data?
# 3  
Old 03-28-2013
Hi,

I just want the XML to end in the same indented format as the input. So it looks like XML etc (which is handy when editing manually).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing custom data into xml in Shell

Hi , I have data as below in a text file { 'AAA' => { 'A1' => 'a1 comment', 'A2' => 'a2 comment' }, 'BBB' => { 'B1' => 'b1 comment' }, 'CCC' => { 'C1' => 'c1 comment', 'C2' => 'c2 comment', 'C3' => 'c3 comment' 'C4' => 'c4... (2 Replies)
Discussion started by: vivek d r
2 Replies

2. Shell Programming and Scripting

Help with parsing data with awk , eliminating unwanted data

Experts , Below is the data: --- Physical volumes --- PV Name /dev/dsk/c1t2d0 VG Name /dev/vg00 PV Status available Allocatable yes VGDA 2 Cur LV 8 PE Size (Mbytes) 8 Total PE 4350 Free PE 2036 Allocated PE 2314 Stale PE 0 IO Timeout (Seconds) default --- Physical volumes ---... (5 Replies)
Discussion started by: rveri
5 Replies

3. Shell Programming and Scripting

Help - Parsing data in XML in Linux

Hi, I have an XML file in Linux and it contains a long string of characters. The last part of the file is like ....... ....... ....... CAD</MarketDescription></InvestorTransaction></AdvisorAccount></DivisionAdvisor></Division>... (3 Replies)
Discussion started by: naveed
3 Replies

4. Shell Programming and Scripting

Converting variable space width data into CSV data in bash

Hi All, I was wondering how I can convert each line in an input file where fields are separated by variable width spaces into a CSV file. Below is the scenario what I am looking for. My Input data in inputfile.txt 19 15657 15685 Sr2dReader 107.88 105.51... (4 Replies)
Discussion started by: vharsha
4 Replies

5. UNIX for Dummies Questions & Answers

Bash script to insert data into an html table

hi, I need to create a bash shell script which picks up data from a text file and in the output file puts it into an html made table. I have to use sed and awk utilties to do this the input text file will contain data in the format: job name para1 para2 para3 para4 para4 1 ... (1 Reply)
Discussion started by: intern123
1 Replies

6. Shell Programming and Scripting

parsing data from xml file is failing can't open variable

Created a korn shell script, everything is is working except this section, the variable $SYSINFO is being set, but the NASIP & NASDEV are failing, it appears to be treating the config.xml file config directory and xml as the file. Need a second set of eyes to tell me where I am messing up. #... (3 Replies)
Discussion started by: juanb25
3 Replies

7. Shell Programming and Scripting

Parsing dynamic data from a command output

Hi people, I am writing a korn shell script, and one of the command gives an output something like below: release.label.2010.03.02 objects: /project/path/to/some/file_name.ksh /project/path/another/file_name01.dat I have to retrieve the file paths one by one & use them as... (9 Replies)
Discussion started by: kiwin1000
9 Replies

8. Shell Programming and Scripting

Parsing posted XML data from a remote server?

Hi Is it possible to parse a posted xml data from a remote server in unix shell script. if so how to do that? and i need to give this script path in the push url (in remote server) . how to do this? I have tried this in asp but could not succeed....so am trying in shell scripting...the thread... (1 Reply)
Discussion started by: aemunathan
1 Replies

9. Shell Programming and Scripting

Parsing and getting data from XML file using ksh script

Hi All, I have a xml file for example as described below <xml> <address> <street><street> <address/> <isbn>426728783932020308393930303</isbn> <book> <name> </name> </book> . . . </xml> My problem is to get the isbn number from the above described file using ksh script. Could... (6 Replies)
Discussion started by: vinna
6 Replies

10. UNIX for Dummies Questions & Answers

Parsing XML dynamic data via awk?

I am trying to use a line of output in an XML file as input in another new XML file for processing purposes via a shell script. Since I am a newbie though, I'm not sure how to do this since the data is different everytime. I am using this technique with static data right now: echo -n "Running... (5 Replies)
Discussion started by: corwin43
5 Replies
Login or Register to Ask a Question