wannabemonk has asked for the wisdom of the Perl Monks concerning the following question:
dataset 1: vr 1 2 3 5 o1 a a b b o2 c c d d o3 e e f f dataset 2: id date1 age 1 2005 30 2 2006 25 3 2005 22 4 2004 23 5 2006 25 merged/tranposed dataset: id date1 age o1 o2 o3 1 2005 30 a c e 2 2006 25 a c e 3 2004 22 b d f 4 2004 23 5 2006 25 b d f
$ids = `head -1 dataset1`; @matchid = split(" ", $ids); shift(@matchid); open(IN, "dataset2" ) || die open(OUT, ">mergeddataset") || die ; $line=<IN>; chomp $line; $h = `cut -f1 dataset1`; @header = split(/\n/,$h); shift(@header); print OUT $line." ".join(" ",@header)."\n"; while ($line=<IN>) { chomp $line; @match=split(" ",$line); foreach $id (@header) { if ($id eq $match[1]) { $column=`head -1 dataset1|tr -s "\t" "\n" | grep -n $id|cut +-f1 -d":"`; chomp $column; $a = `cut -f$column dataset1| tail +2 | tr -s '\n' ' '`; chomp $a; @b = split(/ +/, $a); print OUT $line." ".join(" ",@b)."\n"; } } } close(OUT); close(IN);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: transposing and matching large datasets
by BrowserUk (Patriarch) on Aug 08, 2007 at 22:14 UTC | |
by Anonymous Monk on Aug 09, 2007 at 18:08 UTC | |
|
Re: transposing and matching large datasets
by GrandFather (Saint) on Aug 08, 2007 at 20:44 UTC | |
by wannabemonk (Initiate) on Aug 08, 2007 at 21:00 UTC | |
by moritz (Cardinal) on Aug 09, 2007 at 07:10 UTC | |
by BrowserUk (Patriarch) on Aug 09, 2007 at 07:30 UTC |