Generating XMLfile using shellscript

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Generating XMLfile using shellscript
# 1  
Old 11-04-2009
Generating XMLfile using shellscript

I have a text file in the following form and i want to store it in 2-d array. After that i have to generate a XMLfile using the elements of array.
Please tell me :how store this file in the form of 2-d array and then howto generate XML file using that array...all coding has to be done in bash shell

Text file: Let Name be : Test.txt

Abc Def Ghi Jkl
Lmn Nop Qrs Tuv
... ... ... ...
... ... ... ... (anynumber of records )

The array should be like that

arr[0][0] =Abc arr[0][1]=Def arr[0][2]=Ghi arr[0][3]=Jkl
arr[1][0] = Lmn arr[1][1]= Nop ........ ........
...... ...... ........ ...........

Then XML format is known to me i to generate XMLfile using that array elements...

Note : You can suggest any other form of data structure for storing information (Text File) but should be 2-d ,but please also mention about how to generate XMLfile ...
# 2  
Old 11-04-2009
Post the output format that your expecting , since i am not familiar with the XML format.
# 3  
Old 11-04-2009
XML output format

the format of XML is

< Field1 name="Abc">
<Otherfield name="Def"><\Otherfield>
<Otherfield name="Ghi"><\Otherfield>
<Otherfield name="Jkl"><\Otherfield>
<Field2 name="Lmn">
<Otherfield name="Mno"><\Otherfield>
<Otherfield name="Pqr"><\Otherfield>

I hope its clear that Abc , Def .... above are the values that has to be retrieved form 2-d array and has to be placed in its proper place

plzz feel free to ask any other question
# 4  
Old 11-04-2009
Never worked in array kind of stuff,

Might be this one will be useful.
awk  '{cou++;for(i=1;i<=NF;i++)
{ if(i==1) { print "< Filed"cou" name=\"" $1 "\">" } 
  else {print "<Otherfield name=\"" $i "\"><\Otherfield>" } 
} {print "<\Filed"cou">" }
} '  file_name.txt

# 5  
Old 11-04-2009
There are no 2D arrays in bash. It would be simplier to make the xml file directly by processing the input file.
Say if you want to do so.
# 6  
Old 11-04-2009
panyam almost there Smilie
# awk  'BEGIN{print "<data>"}
{ if(i==1) { print "< Filed"cou" name=\"" $1 "\">" }
  else {print "<Otherfield name=\"" $i "\"><\Otherfield>" }
} {print "<\/Filed"cou">" }
} END{print "<\/data>"}' flatfile

# 7  
Old 11-04-2009
Thanks "danmero" . I missed the "data" part. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Telnet shellscript

cat << EOF | telnet 25 HELO MAIL FROM: <> RCPT TO: <> quit EOF Hello, I'm trying to get the result of that execution, and can not see the result or bring it to a txt ... the direct command in ssh running the result... (5 Replies)
Discussion started by: c0i0t3
5 Replies

2. Shell Programming and Scripting

Help with shellscript

I am new in shell script i want to convert .txt file in the format axsjdijdjjdk to a x s j d i j d j j d k (5 Replies)
Discussion started by: sreejithalokkan
5 Replies

3. Shell Programming and Scripting

Needed shellscript for the following

hi all, i need the shell script for he below requirement i had the input file as a_20121217_035120( frmat is a_date_hhmmss) a_20121217_035128 a_20121217_035456 a_20121217_035767 a_20121217_035178 a_20121217_035189 a_20121217_035220 my output should be a_20121217_035456... (0 Replies)
Discussion started by: hemanthsaikumar
0 Replies

4. Post Here to Contact Site Administrators and Moderators

help with backup shellscript

can any one advice on this.. create archive backup the directory "backup" that includes the following directory " product/dev","product/uat"and product/maintain", yymmdd, stand for current date This archive needs to be perpared at 9PM every day Thanks advance (1 Reply)
Discussion started by: ksakil
1 Replies

5. Shell Programming and Scripting

Shellscript Reengineering

Dear Community, I've an urgent issue due to a migration of an application from HP-Unix to Linux. We have a mass of scripts which are running at a dedicated server on hpunix. Now we do not know, which further scripts exists on this machine. the idea is, that we crawl through the scripts we... (1 Reply)
Discussion started by: Alibapir
1 Replies

6. Shell Programming and Scripting

Need help with shellscript

Hello. I am a novince at writing shell scripts but here is the question. I have to write a shell script that does the following: Once executed via crontab, the script should do the following: a. get date/time stamp in for format 10-MAR-05 and b. execute shell script (which... (2 Replies)
Discussion started by: jigarlakhani
2 Replies

7. Shell Programming and Scripting

XMLfile parsher

Hi all Does anyone know how I can parse an xml file and get only some data? For example: <?xml version="1.0"?> <!--?xml-stylesheet type="text/xsl" href="irpexamle.xsl"?--> <mdc> <md> <neid> <neun></neun> <nedn></nedn> </neid> <mi> ... (2 Replies)
Discussion started by: jacost
2 Replies

8. Shell Programming and Scripting

Create Shellscript

I am new to UNIX. I got the file from Oracle, with two columns (Table Name and Column Name). I need to create the shell script where the result suppose to include plain text, <table_name>, <Column_name> from the file. Plain text will be the statements to create index in Oracle. something like... (1 Reply)
Discussion started by: newuser100
1 Replies
Login or Register to Ask a Question