ikhan has asked for the wisdom of the Perl Monks concerning the following question:
PerlMonks: Thanks for all the help.
I have another question. I am trying to merge a given column from individual lfiles to a single text file. This is how the files look like:
input1
freq data1
1 2
2 5
3 10
input2
freq data2
1 12
2 50
3 10
input3
freq data3
1 10
2 25
3 11
Combined output
freq data1 data2 data3
1 2 12 10
2 5 50 25
3 10 10 11
I have difficulty writing to a certain column in output
following code attempts to take second column from input file and writes to second column in output file, but not successful.
use strict; use warnings; open(my $file2, '<', "data1.txt") or die "failed to open 'output_1.txt + $!"; open(my $file3, '>>', "combined.txt") or die "failed to open 'combined +.txt $!"; while (<$file2>) { chomp; # delete new line character my @combined_data = $file3; my @list_file = split; print "$combined_data[1]" "$list_file[1]\n"; } close $file2; close $file3;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Merging Columns from multiple files into a single file
by davido (Cardinal) on Oct 18, 2015 at 19:31 UTC | |
|
Re: Merging Columns from multiple files into a single file
by AppleFritter (Vicar) on Oct 18, 2015 at 19:20 UTC | |
by ikhan (Initiate) on Oct 20, 2015 at 05:18 UTC | |
by poj (Abbot) on Oct 20, 2015 at 06:33 UTC | |
by AppleFritter (Vicar) on Oct 20, 2015 at 10:09 UTC | |
|
Re: Merging Columns from multiple files into a single file
by kevbot (Vicar) on Oct 18, 2015 at 21:51 UTC |