Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How to merge two files like the following with the XML parser

Re: How to merge two files like the following with the XML parser

From: stephen O'D <stephen.odonnell_at_gmail.com>
Date: 28 Oct 2005 01:29:22 -0700
Message-ID: <1130488162.544520.305570@g43g2000cwa.googlegroups.com>

karenmiddleol_at_yahoo.com wrote:
> I have two text files.
>
> I want to merge them together as follows:
>
> ================================
> File1.txt
>
> SCREEN,
> PROGRAM,
> FIELD1,
> VALUE1,
> FIELD2,
> VALUE2,
> FIELD3,
> VALUE3,
> ================================
>
>
> ================================
> File2.txt
>
>
> S1,P1,F11,V11,F12,V12,F13,V13
> S2,P2,F21,V21,F22,V22,F23,V23
> ...
> ...
>
> ================================
>
> Now when I merge the two files together I want the following file:
>
> ================================
> File3.txt
>
>
> SCREEN, S1
> PROGRAM,P1
> FIELD1,F11
> VALUE1,V11
> FIELD2,F12
> VALUE2,V12
> FIELD3,F13
> VALUE3,V13
> SCREEN, S2
> PROGRAM,P2
> FIELD1,F21
> VALUE1,V21
> FIELD2,F22
> VALUE2,V22
> FIELD3,F23
> VALUE3,V23
>
>
> =======================================================
>
>
> I want a generic script that can merge file1.txt and file2.txt to
> generate file3.txt
>
>
> I want a script that can take a template of File1.txt as follows:
>
>
> SCREEN, <<S>>
> PROGRAM, <<P>>
> FIELD1, <<C1>>
> VALUE1, <<C2>>
> FIELD2, <<C3>>
> VALUE2, <<C4>>
> FIELD3, <<C5>>
> VALUE3, <<C6>>
>
>
> =======================================================
>
>
> and the file2.txt to identify what goes to <<S>>, <<P>>
> in the following form:
>
> ================================
> File2.txt
> <<P>>,<<S>>,<<C1>>,<<C2>>,<<C3>>,<<C4>>,<<C5>>,<<C6>>
> S1,P1,F11,V11,F12,V12,F13,V13
> S2,P2,F21,V21,F22,V22,F23,V23
> ...
> ...
>
> =======================================================
>
>
> So I want a generic XML parser based utility that can accept three
> arguments for file1, file2 and file3 and can merge the template of
> file1 to the contents in file2 to be substituted in file1 to generate
> file3.
>
>
> Appreciate if any of you can kindly share code to get the XML parser
> to do this which most of you would have faced with such a similar
> problem.
>
> It is almost like a mail merge but the data volumes can be large and it
> is not practical to use MS Word.
>
> To keep it simple I want the whole merge process in XML parser.
>
> Appreciate if you could kindly share how to get this done with the XML
> parser.
>
>
> Thanks
> Karen

Karen,

I don't think this is a XML parser problem, as these files are not in an XML format. If you need to merge files a lot of files like this, I personally would not use Oracle, but something more suited to the task, like Perl for instance. In saying that however, you may be able to the load the files into the database using the external table functionality and manipulate them using SQL.

Also, I don't know the background of the problem, but do you really need fields 1 and 3? Could you not format file 2 as follows:-

SCREEN,PROGRAM,FIELD1,VALUE1,FIELD2,VALUE2
S1,P1,F1,V1,F2,V2
S1,P1,F1,V1,F2,V2
S1,P1,F1,V1,F2,V2

...

ie, file two contains on the first line the name of each field and each subsequent line contains the value for each field. This is effectively what file 3 is going to be anyway, only layed out differently, only this way you need 1 file and don't need to merge them!

Stephen. Received on Fri Oct 28 2005 - 03:29:22 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US