• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Making multiple files from single file

 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a xml file in which there is data from multiple tables.
The file looks like --
test.xml

I want to make two file from this
Activities.xml and second Contact.xml

Activities.xml will have

And Contact.xml will have

The number of rows in each table will vary. Also there are more than two tables , so tags like Activity and Contact can be many, each one having many rows.
I need to create sepearte file for each of these main tags.

Is it possible to do it using shell script? Or should I be using something else?

Please help
Thanks!

[ EJFH: Fixed up code samples. ]
[ September 27, 2004: Message edited by: Ernest Friedman-Hill ]
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These files don't look like xml at all.
Are you sure, that that's the real content of the files, and not only the rendered output of some tool?

If the format is allways

(int)
(date)
X

or:

V(int)
no3-no3-no4

a script, reading the file and evaluating regex should work.
Do you use bash?

I guess awk is the best tool to do the work, but I'm not well in awk.
Here is a sed-solution, which will eliminate the blanks:


Note that I inserted 3 CRs into the statements, which shall avoid an endless line here in the forum, which you have to remove for the script to work.
And for the time, the pattern could be made more restrictive.
[ September 27, 2004: Message edited by: Stefan Wagner ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
His files were indeed XML, but this forum is one of the few at the Ranch which allows HTML tags in messages, so all his XML elements were being ignored as unknown HTML tags! I fixed them all up.
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ernest for fixing the files!

Thanks Stefan for your input.

I do not use bash. Infact I am very much a newbie with unix shell scripts.
If you could give code / code snippet for doing this that will be very helpful.

THanks once again!

Gemini
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, the best solution is probably to use XSLT. I beleive that the program in question is "xslide", but I can't bet to my Linux box to check.

Of course, whether it's more painful to built XSLT templates or simply hack and slash your way through raw text using AWK or Perl (hint: check CPAN for XML support packages) is debatable.
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ernest Friedman-Hill , Can you please move this thread to XML forum?

If someone can give me some heads up with how I can write XSLT for this.

I can use Oracle Pl SQL or Java Stored procedures in my project here.

Is it possible to do this using Plsql ? how efficient will that be?

Thanks!
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can certainly move this to XML.

The XSLT would be pretty simple -- I'll see if I have time to come back later and talk about it.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He he - teaching the xml-people a little bit linux-bash:


replace

with


like to see a simpler solution using xml-libs.
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the advantages of using XSLT is that you are guaranteed to get a valid XML as input (consequently in this example as output), which your example is not.

<CREATED_BY>X</CREATED_DT>
should probably be

<CREATED_BY>X</CREATED_BY>?

And then, you missed the top level element.

After fixing this, your XSLT 1.0 solution will be


replace match="Activities" with "Contacts" for Contact.xml.
 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am confused about this one still.

Here are further details.
The file that I have is a huge file with data from many tables.
Basically I have to load this xml file into Oracle tables.
I have written Oracle Pl sql procedure using XML_Save pacakge to achive loading of data given, file name (file should have data only from one table), and table name to which the data should be loaded.

Now the problem I am facing is, the file that our system will receive will have data from all the tables together. Not that I will get seperate file for each table. Henc I thought of breaking the files into various files such that each file will have data from only one table.

I tried to do it using Unix shell scripts. But have not been successful yet. Reason being --
The file that our system is receiving will all this data in single line (with no newline character at all) (Isn't it crazy???)
Also the file size is around 5MB.

Any suggestions as to what should I use to break this file.
The contets of the files will vary (Sometime Activity table will not have any data in it to no rows with <Activities> tag will be there.
Hence if I understand correctly both he solutions suggested above are not able to handle this dynamic nature of the file.

I have tried using sed in Unix but it did not work due to I guess file size and basically this dumb file having no newline characters in it.


Please help!

Thanks

[ October 01, 2004: Message edited by: Gemini Moses ]
[ October 01, 2004: Message edited by: Gemini Moses ]
reply
    Bookmark Topic Watch Topic
  • New Topic