The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed Problem in Shellscript urukai Shell Programming and Scripting 5 08-08-2008 07:14 AM
Need help with shellscript jigarlakhani Shell Programming and Scripting 2 11-22-2007 08:28 AM
Another shellscript question jigarlakhani Shell Programming and Scripting 18 11-30-2005 10:50 AM
XMLfile parsher jacost Shell Programming and Scripting 2 10-01-2004 06:44 PM
ftp in Shellscript ggowrish UNIX for Advanced & Expert Users 3 06-11-2004 09:09 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
cynosure2009 cynosure2009 is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 14
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 (permalink)  
Old 4 Weeks Ago
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Post the output format that your expecting , since i am not familiar with the XML format.
  #3 (permalink)  
Old 4 Weeks Ago
cynosure2009 cynosure2009 is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 14
XML output format

the format of XML is


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


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 (permalink)  
Old 4 Weeks Ago
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Never worked in array kind of stuff,

Might be this one will be useful.

Code:
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 (permalink)  
Old 4 Weeks Ago
frans's Avatar
frans frans is offline
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 113
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 (permalink)  
Old 4 Weeks Ago
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,439
panyam almost there

Code:
# awk  'BEGIN{print "<data>"}
{cou++;for(i=1;i<=NF;i++)
{ if(i==1) { print "< Filed"cou" name=\"" $1 "\">" }
  else {print "<Otherfield name=\"" $i "\"><\Otherfield>" }
} {print "<\/Filed"cou">" }
} END{print "<\/data>"}' flatfile

  #7 (permalink)  
Old 4 Weeks Ago
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Thanks "danmero" . I missed the "data" part.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0