Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

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

Hi, just joined minutes ago. I am trying join tab-delimited files into a single file/table

Example, say I have these 4 files/tables:

ID value (table1)

Aa 22

Bb 28

Cc 32

Dd 50

ID value (table2)

Aa 34

Cc 112

Dd 77

Ee 89

Kk 124

ID value (table3)

Bb 75

Cc 91

Dd 132

ID value (table4)

Aa 66

Cc 94

Ee 213

Gg 250

The output after joining should look like this:

ID value1 value2 value3 value4

Aa 22 34 0 66

Bb 28 0 75 0

Cc 32 112 91 94

Dd 50 77 132 0

Ee 0 89 0 213

Gg 0 0 0 250

Kk 0 124 0 0

My best effort:

#usr/bin/perl! use strict; #I opened all files (containg the tables) one by one; is #there a way +I can open all files at once? open(FILEH1, "<table1.txt"); while (my $file = <FILEH1>){ chomp $file; my @file1 = split('\t', $file); #to pick IDs and #values => $fil +e1[0] and $file1[1] } open(FILEH2, "<table2.txt"); #and continued to tables 3 and 4. #And then I tried to collect the items which is where I got #stuck.

In reply to I need help joining tab-delimited files/tables! by nabiana

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 scrutinizing the Monastery: (5)
As of 2024-04-24 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found