Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

( #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

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (5)
    As of 2021-04-13 12:38 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found