Generating XMLfile using shellscript


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Generating XMLfile using shellscript
# 8  
Old 11-04-2009
a bash script
Code:
{	J=1
	echo '<data>'
	while read LINE
	do
		VAR=( $LINE )
		echo '<Field'$J' name="'${VAR[0]}'"><\Field'$J'>'
		for I in 1 2 3
		do	echo '<OtherField name="'${VAR[$I]}'"><\Otherfield>'
		done
		echo '<\Field>'
	done < InputFile1
	echo '<\data>'
} > OutputFile.xml

# 9  
Old 11-04-2009
Reply to Frans

ok frans ... please tell me to generate xml file directly

---------- Post updated at 07:09 AM ---------- Previous update was at 07:01 AM ----------

thanks frans ... its working ...

---------- Post updated at 07:35 AM ---------- Previous update was at 07:09 AM ----------

Quote:
Originally Posted by panyam
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



This is not showing me any input ..
plzz tell me the command to execute this awk file
also where to see the output
# 10  
Old 11-04-2009
Ok. Copy the above mentioned awk script and put it in any file , for example : scrpt.sh and then run the script as :

Code:
. script.sh

Dont forget to replace the "file_name.txt" in the script with your input file name.
# 11  
Old 11-04-2009
If you really want to generate a XML your syntax is wrong. Closing elements
should start with "</" - not "<\" i.e.
Code:
#!/bin/bash

n=1;

echo "<data>" > outfile
while read f o1 o2 o3
do
   echo "<Field$n name="\"$f\"">" >> outfile
   echo "<Otherfield name="\"$o1\""></Otherfield>" >> outfile
   echo "<Otherfield name="\"$o2\""></Otherfield>" >> outfile
   echo "<Otherfield name="\"$o3\""></Otherfield>" >> outfile
   echo "</Field$n>" >> outfile
   n=$((n+1))
done < infile
echo "</data>" >> outfile

# 12  
Old 11-04-2009
Not working

# 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


This code is not working ... i am using name of my file instead
of flatfile .. plzz tell me way to execute this file..
like what should be the extension what should be the command for executing this file

---------- Post updated at 10:25 PM ---------- Previous update was at 10:16 AM ----------

thanks for helping me .. but i have to store the contants of that file in a data structure ... plzz tell me a way to store the contents in data structure and then generate aXML file form it..
# 13  
Old 11-05-2009
awk itself is a "command" , yo do not need any thing else to execute it.

Just copy paste the thing what ever we have posted and execute the script.
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>"}'  file_name.txt

I am not sure of any data structures for storing these elements.
# 14  
Old 11-05-2009
Sorry for spoiling the discussion at the last moment.

This is not a scalable and fail proof way to create XML formats. Instead well supported already created modules are available from CPAN
Probably you could start of with XML::Simple

It is very simple to complete your task
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 alt1.aspmx.l.google.com 25 HELO verify-email.org MAIL FROM: <check@verify-email.org> RCPT TO: <test@gmail.com> 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 -yyyymmdd.tr.gzin 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 my_script.sh (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