Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
How would I open two files and join then into one file with file 1 output being column 1 and file 2 being column 2. for example:
file 1 looks like this
123455 c c
323333 c c
543212 c c
and
file 2 looks like this
fi1234 4 3
dtt234 4 3
3555t2 4 3
and i would want my joined file to look like this
123455 c c fi1234 4 3
323333 c c dtt234 4 3
543212 c c 3555t2 4 3
Ive tried something like the following which did not work.
This printed everything in file 1 three times. Thanks for any help.open(IN, "file1") || or die; open(IN2, "file2") || or die; open(OUT, ">>joinfile") || or die; for my $file1 (<IN>) { chomp $file1; for my $file2 (<IN2>) { chomp $file2; print OUT "$file1 $file2\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: joining to files into columns
by diotalevi (Canon) on May 18, 2006 at 22:29 UTC | |
| |
|
Re: joining to files into columns
by runrig (Abbot) on May 18, 2006 at 22:25 UTC | |
|
Re: joining to files into columns
by GrandFather (Saint) on May 18, 2006 at 22:55 UTC | |
|
Re: joining to files into columns
by johngg (Canon) on May 18, 2006 at 22:23 UTC | |
|
Re: joining to files into columns
by rodion (Chaplain) on May 18, 2006 at 22:15 UTC | |
by blazar (Canon) on May 19, 2006 at 10:09 UTC | |
|
Re: joining to files into columns
by dsheroh (Monsignor) on May 18, 2006 at 22:38 UTC | |
by runrig (Abbot) on May 18, 2006 at 22:45 UTC |