![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 06: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 05:44 PM |
| ftp in Shellscript | ggowrish | UNIX for Advanced & Expert Users | 3 | 06-11-2004 08:09 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 ... |
|
||||
|
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 |
|
||||
|
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
|
|
||||
|
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
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|