Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to concatenate two files

Status
Not open for further replies.

babs

Programmer
Dec 29, 2000
7
US
Hi,
I need to take two files and make one file.
The first record has records 1-9; the second record has records 1-9.
How can I write this in Perl to have the total for the first file follow the eight record and
the second file 1-9 records to follow with its total.

I hope this is clear.

Thanks in advance
Babs
 
' sounds like this might be trivial , but I don't understand the question yet.....

Code:
#!/usr/local/bin/perl

open(IPF1,&quot;<file1&quot;) or die &quot;Failed to open file1, $!\n&quot;;
while (<IPF1>) { $buff1 .= $_; }
close IPF1;

open(IPF2,&quot;<file2&quot;) or die &quot;Failed to open file2, $!\n&quot;;
while (<IPF2>) { $buff2 .= $_; }
close IPF2;

open(OUTPUTFILE,&quot;>file3&quot;) or die &quot;Failed to open file3 for writing, $!\n&quot;;
# do what you need to rearrange the contents of buff1 
# and buff2 and print them to the new file.
print OUTPUTFILE &quot;$buff1 $buff2&quot;;
close OUTPUTFILE;

Given a little clearer explaination of what you need we/I can add more meat to this.

HTH


keep the rudder amid ship and beware the odd typo
 
Didn't we just answer a question about concatenating files?
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Babs -- that isn't clear I'm afraid, unless goBoating managed to be psychic there :)

Could you put your question a different way please? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
I might be psychotic but I pretty sure I'm not psychic..... unless, of course, I am....X-)


keep the rudder amid ship and beware the odd typo
 
Hi,

I am trying to write a perl script to take two files and make it into one file. The first file has record types 1-9.
The nine record has the total record count for the file.
The second file has record types 1-9. The nine record should have the totals of both files.

This is some of my coding:


my $newfile = &quot;hershey.dat&quot;;
my #slash = &quot;/&quot;;
my #opr = &quot;>&quot;;
my $datfile = join(&quot;&quot;, $outputdir,$slash, $outfile);
my $newfile = join(&quot;&quot;, $opr, $outputdir, $slash, $newfile);
my @records = 0;
my @line = 0;
my $records =0;
my $type = 0;

open (BFILE, $datfile) or die &quot;could not open $datfile\n&quot;;
@records = <BFILE>;
close(BFILE);

print $newfile ,&quot;\n&quot;;
open(NFILE, $newfile) or die &quot;could not open BAI.DAT\n&quot;;

foreach $records(@records) {
$type = substr ($records)
if ($type eq '1') {


Thanks
 
.....sorry babs, you're really going to have to give us more information for us to figure this out. show us a sample of what each file looks like, then what you want the output to looklike after you're done &quot;concatenating&quot; them. it just isn't possible from the terminology you're using to understand what the data and task you're dealing with are. &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top