Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

Joining two files in rexx

santum
Occasional Visitor

Joining two files in rexx

I have to create one map(say MAP 1) taking map 2 and map 3 as input and join them to create the map 1 in REXX.
5 REPLIES
Steven Schweda
Honored Contributor

Re: Joining two files in rexx

VMS is different from MVS, and it's not
Windows, either. Are you in the right forum?
Andy Bustamante
Honored Contributor

Re: Joining two files in rexx

Are you working with Fidelity's RE/X?

Andy
If you don't have time to do it right, when will you have time to do it over? Reach me at first_name + "." + last_name at sysmanager net
Hein van den Heuvel
Honored Contributor

Re: Joining two files in rexx

Santum,

You are probably submitting this question to the wrong forum. Please elaborate as to what rexx might stand for. What platform, what tool, and if you care about a solution, what specific join requirements (sort order, duplicates,...).

Is this pertaining a windows style ini file a per:

http://cwashington.netreach.net/depo/view.asp?Index=525&ScriptType=rexx


If so, I suspect your best bet is to simply use an editor to manually merge.

If I were to write a script to do this then I woudl use perl and exploit 'Hash of Arrays' to name each group and add line to those group. I don't know what you should do with dups (retain first, last, both?)

See for example: http://www.ayni.com/perldoc/perl5.8.0/pod/perldsc.html


Sample perl solution:

------------------------ test.pl ---------
while ($file = shift) {
open FILE, "<$file" or die "Could not open file $file";
$key = " ";
push @{ $HoA{$key} }, "\n/* Entries from $file */\n";

while () {
if (/^\[\w+\]$/) {
$key = $_;
push @{ $HoA{$key} }, "\n/* Entries from $file */\n";
} else {
push @{ $HoA{$key} }, $_;
}
}
}

foreach $key (sort keys %HoA) {
print "$key\n", join ("", @{$HoA{$key}}), "\n";
}

----------

Sample usage

perl test.pl map2.ini map3.ini > map1.ini


The above script adds traces to show whre sections came from. Without that it could read:
------------------------ test.pl ----------
while ($file = shift) {
open FILE, "<$file" or die "Could not open file $file";
$key = " ";
while () {
if (/^\[\w+\]$/) {
$key = $_;
} else {
push @{ $HoA{$key} }, $_;
}
}
}

foreach $key (sort keys %HoA) {
print "$key", @{$HoA{$key}};
}
Nyle Davis
Occasional Visitor

Re: Joining two files in rexx

S,

Which version of REXX are you using. Code will very by version.
Nyle Davis
Occasional Visitor

Re: Joining two files in rexx

S,

A sample in OO-REXX would be:

files = "file1 file2"; z=0
do n=1 to words(files)
curfil = word(files,n)
rc = SysFileTree(curfil, 'inpfil', 'FO')
if rc = 0 & inpfil.0 > 0 then do xx = 1 to inpfil.0
ReadFile = .stream~new(inpfil.xx)
ReadFile~open("READ")
do while ReadFile~lines() > 0
z = z + 1
oline.z = strip(ReadFile~linein)
end /* end do do while */
ReadFile~close
end /* end if rc=0 */
end /* end do n=1 */
WFile = .stream~new(outfil)
WFile~open("WRITE")
do y =1 to z
WFile~lineout(oline.y,y)
end /* end do n= */
WFile~close

If you are on mainframe "linein" and "lineout" still work, but syntax is diff and you have to load the file via "EXECIO" on some systems.