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

Join Date: Sep 2008
Posts: 474
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.
  #3 (permalink)  
Old 4 Weeks Ago
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,935
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

  #4 (permalink)  
Old 4 Weeks Ago
frans's Avatar
frans frans is offline
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 113
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

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 11:47 AM.


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