Dear monks,

Today at $work I came across a little problem that I assumed was trivial but seems to be not so trivial after all.

I have two files with the same number of corresponding lines (rows) and differing columns. What I wanted to do was take a column from one file and add it as a column to the second file. For example:

% cat file_one chr coord array value 1 100 5730_1 0.123 1 200 5730_1 4.567 ... 21 400 5785_3 2.345 % cat file_two chr coord new_annotation 1 100 1 1 200 1 ... 21 400 60 % cat out_file chr coord new_annotation value 1 100 1 0.123 1 200 1 4.567 ... 21 400 60 2.345

I had intended to use a unix cut command but that only takes one file as an argument. I wanted something like this post or a module that does something similar. I've looked but as yet have not found something straight forward enough.

Does this look familiar to anyone or do I have to write my own application that goes:

perl -MMy::App -e 'merge( file_one=>\@cols_one, file_two=>\@cols_two ) +;

and produces a file that combines all the selected columns from file_one and file_two?

Thanks all in advance


Smoothie, smoothie, hundre prosent naturlig!

In reply to merge files by column (revisted) by j1n3l0

Title:
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, details, 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, summary, 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.