Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Create 26 sample files, 10 columns, 2000 rows:

for my $letter ('A'..'Z') { my $file = "tmp/$letter.txt"; open my $fh, '>', $file or die "No open > $file: $!"; say $fh join "\t", 'Gene', map "exp$_", 1..10; for my $i (1..2000) { say $fh join "\t", $i, map "$letter-$i-exp$_", 1..10; } }

First lines of A.txt:

Gene exp1 exp2 exp3 exp4 exp5 exp6 exp7 exp8 + exp9 exp10 1 A-1-exp1 A-1-exp2 A-1-exp3 A-1-exp4 A-1-exp5 A-1-e +xp6 A-1-exp7 A-1-exp8 A-1-exp9 A-1-exp10 2 A-2-exp1 A-2-exp2 A-2-exp3 A-2-exp4 A-2-exp5 A-2-e +xp6 A-2-exp7 A-2-exp8 A-2-exp9 A-2-exp10 ...

Append exp4 column from each file to end of lines:

@ARGV = <tmp/*.txt>; my %row; while (<>) { my ($gene, $exp4) = (split /\t/)[0,4]; $row{$gene} .= "\t$exp4"; } delete $row{Gene}; say "$_$row{$_}" for sort {$a <=> $b} keys %row;

First lines of output:

1 A-1-exp4 B-1-exp4 C-1-exp4 D-1-exp4 E-1-exp4 F-1-e +xp4 G-1-exp4 H-1-exp4 I-1-exp4 J-1-exp4 K-1-exp4 L- +1-exp4 M-1-exp4 N-1-exp4 O-1-exp4 P-1-exp4 Q-1-exp4 + R-1-exp4 S-1-exp4 T-1-exp4 U-1-exp4 V-1-exp4 W-1-exp4 + X-1-exp4 Y-1-exp4 Z-1-exp4 2 A-2-exp4 B-2-exp4 C-2-exp4 D-2-exp4 E-2-exp4 F-2-e +xp4 G-2-exp4 H-2-exp4 I-2-exp4 J-2-exp4 K-2-exp4 L- +2-exp4 M-2-exp4 N-2-exp4 O-2-exp4 P-2-exp4 Q-2-exp4 + R-2-exp4 S-2-exp4 T-2-exp4 U-2-exp4 V-2-exp4 W-2-exp4 + X-2-exp4 Y-2-exp4 Z-2-exp4 ...

In reply to Re: Is there any efficient way i can take out a specific column from hundreds of files and put it in one file? by Anonymous Monk
in thread Is there any efficient way i can take out a specific column from hundreds of files and put it in one file? by coolda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-18 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found