Answer» Hello,
I'm new to *ix. Basically, I stumble through scripts that other people write and TRY to figure how they did things. Right now I'm a little stumped and am hoping someone can write what would probably be a simple shell script for them. What I need it to convert an excel doc (or tab delimited doc if excel is to crazy) into an xml format. I know this sounds difficult, but it should be easy when you realize the format.
All I need is this format. The first tags can read exactly as they are and do not require getting any outside info:
Code: [Select]<opening tag> <2ndopening tag> <item=clip> <attributes>
Now comes the part that REQUIRES getting info from the outside document:
Code: [Select] <attribute key="value of column A">values of columns B, C and D</attributes>
The only trick would be that if the value of any columns is empty I'll need a space. I'll need that to run until it reaches a POINT where there are no values in any column and then I'll need to close the tags from the first code part of this post.
If someone could help I'd really appreciate it.
Thanks,
Dan What have you got so far? And what scripting language are you using?This actually works, but it's probably obvious to a pro that a beginner wrote this. If I could get an evaluation it would be great. There are also a couple parts MISSING that I'm stumped on.
Code: [Select]#First, let's create the document and write in the opening tags.
touch update.xml
#Let's make the file read and write only for everyone
chmod 666 update.xml
#Let's drop in the opening tags
echo "<xml version=1.1>" >> update.xml #xml tag echo " <items>" >> update.xml #items tag echo " <item name="test.mov">" >> update.xml #item name echo " <Attributes>" >> update.xml #Attributes tag #let's get rid of some special characters
tr '\r' '\n' < /users/ddow/Desktop/CLI_Workflows/test/Continuity.txt > sanitized.tmp
awk '{sub("&","and"); print}' /users/ddow/Desktop/CLI_Workflows/test/sanitized.tmp > /users/ddow/Desktop/CLI_Workflows/Up_All_Night/sanitized2.tmp
awk '{sub(":","-"); print}' /users/ddow/Desktop/CLI_Workflows/test/sanitized2.tmp > /users/ddow/Desktop/CLI_Workflows/Up_All_Night/sanitized3.tmp
#Let's create our xml file
awk -F "\t" '{if ($1!=""){printf " <attribute key=\"" $1 "\">"; for (x=2;x<NF;x++) printf $x " "; print "</attribute>"}}' /users/ddow/Desktop/CLI_Workflows/test/sanitized3.tmp >> pix_update.xml
#Dropping in the closing tags
echo " </Attributes>" >> update.xml #Close attributes echo " </item>" >> update.xml #close item echo " </items>" >> update.xml #close items echo "</xml>" >> update.xml #close xml
#Let's get rid of our TEMP files
rm *.tmp
#EOF I still need the code to move the value from row B to row A if row A is empty.
|