develooper Front page | perl.beginners | Postings from January 2002

Re: How to abut two files?

Thread Previous | Thread Next
Jeff 'japhy' Pinyan
January 30, 2002 16:15
Re: How to abut two files?
Message ID:
On Jan 30, Catherine L Harris said:

>One of the most common needs in data analysis is to "abut" two files.  This
>means to create a single file by horizontally pasting two files together.

If you have Perl, the following program does the job:

  #!/usr/bin/perl -w

  die "usage: $0 file1 file2 > output\n" unless @ARGV == 2;

  open LEFT, $ARGV[0] or die "can't read $ARGV[0]: $!";
  open RIGHT, $ARGV[1] or die "can't read $ARGV[1]: $!";

  while (<LEFT>) {
    print $_, scalar <RIGHT>;

  close LEFT;
  close RIGHT;

This of course assumes that the files are the same number of lines.

Jeff "japhy" Pinyan
RPI Acacia brother #734
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About