I have to extract a column from 177 tab delimited huge text files (more than 2MB each) and merge the columns together without appending (meaning I want the columns side by side)
Say I've got:
file1
..
..
file177
Each file has
file1:
A B C D E ...
32.3 34
52.1 352.1
53.65 .
. .
. .
.many rows
file2:
A B C D E ...
52.7 5.1
4.1 12.3
36.3 .
. .
. .
.many rows (20000+ rows)
In each file I want to extract only 1 column say column B.
And the output file is to look like this:
B(file1) B (file2) B(file3) ... B(file177)
34 5.1 .
352.1 12.3 .
. . .
. .
.
(20000+ rows)
The code I've got here merges the columns all in a single row which I don't want ...
#!/usr/bin/perl -w
## path to all files in a directory
@files = <*.txt>;
## output filename in same directory
open (OUTFILE, ">result.txt");
##loop for each file in the array
foreach $file (@files)
{
## read line from each file
open (MYLINE, $file);
## loop each line
while (<MYLINE>)
{
chomp;
##split into columns using with \t
@col = split(/\t/, $_);
print OUTFILE "$col[1]\t";
}
close (MYLINE);
}
close (OUTFILE);
Is there a way to solve this?
Thanks
Say I've got:
file1
..
..
file177
Each file has
file1:
A B C D E ...
32.3 34
52.1 352.1
53.65 .
. .
. .
.many rows
file2:
A B C D E ...
52.7 5.1
4.1 12.3
36.3 .
. .
. .
.many rows (20000+ rows)
In each file I want to extract only 1 column say column B.
And the output file is to look like this:
B(file1) B (file2) B(file3) ... B(file177)
34 5.1 .
352.1 12.3 .
. . .
. .
.
(20000+ rows)
The code I've got here merges the columns all in a single row which I don't want ...
#!/usr/bin/perl -w
## path to all files in a directory
@files = <*.txt>;
## output filename in same directory
open (OUTFILE, ">result.txt");
##loop for each file in the array
foreach $file (@files)
{
## read line from each file
open (MYLINE, $file);
## loop each line
while (<MYLINE>)
{
chomp;
##split into columns using with \t
@col = split(/\t/, $_);
print OUTFILE "$col[1]\t";
}
close (MYLINE);
}
close (OUTFILE);
Is there a way to solve this?
Thanks