Join 将制表符分隔的文本文件合并到单个文件中

Join 将制表符分隔的文本文件合并到单个文件中,join,merge,tabs,delimited,Join,Merge,Tabs,Delimited,将文件夹(以制表符分隔)中的所有文件合并到单个文件中的最简单方法是什么?它们都共享一个唯一的列(主键)。实际上,我只需要在这个主键上组合一个特定的列和链接,这样输出文件就会为每个文件包含一个新的列。例: KEY# Ratio1 Ratio2 Ratio3 1 5.1 4.4 3.3 2 1.2 2.3 3.2 etc.... 每个文件中还有许多其他列,我不需要在输出文件中合并,我只需要这些“比率”列通过唯一键列链接 我正在运行OS X Sn

将文件夹(以制表符分隔)中的所有文件合并到单个文件中的最简单方法是什么?它们都共享一个唯一的列(主键)。实际上,我只需要在这个主键上组合一个特定的列和链接,这样输出文件就会为每个文件包含一个新的列。例:

KEY#  Ratio1  Ratio2  Ratio3
1     5.1     4.4     3.3
2     1.2     2.3     3.2
etc....
每个文件中还有许多其他列,我不需要在输出文件中合并,我只需要这些“比率”列通过唯一键列链接


我正在运行OS X Snow Leopard,但可以访问一些Linux机器。

使用该实用程序

我实际上花了一些时间学习Perl,并自己解决了这个问题。我想如果有人有类似的问题需要解决,我会分享源代码

#!/usr/bin/perl -w

#File: combine_all.pl
#Description: This program will combine the rates from all "gff" files in the current directory.

use Cwd; #provides current working directory related functions
my(@handles);

print "Process starting... Please wait this may take a few minutes...\n";

unlink"_combined.out"; #this will remove the file if it exists

for(<./*.gff>){
  @file = split("_",$_);
  push(@files, substr($file[0], 2));
  open($handles[@handles],$_);
}

open(OUTFILE,">_combined.out");

foreach (@files){
  print OUTFILE"$_" . "\t";
}

#print OUTFILE"\n";

my$continue=1;

while($continue){
  $continue=0;

  for my$op(@handles){
    if($_=readline($op)){
      my@col=split;
      if($col[8]) {
        $gibberish=0;
        $col[3]+=0;
        $key = $col[3];
        $col[5]+=0;  #otherwise you print nothing
        $col[5] = sprintf("%.2f", $col[5]);
        print OUTFILE"$col[5]\t";
        $continue=1;
      } else {
        $key = "\t";
        $continue=1;
        $gibberish=1;
      }
    }else{
      #do nothing
    }
  }
  if($continue != 0 && $gibberish != 1) {
    print OUTFILE"$key\n";
  } else {
    print OUTFILE"\n";
  }
}
undef@handles; #closes all files
close(OUTFILE);

print "Process Complete! The output file is located in the current directory with the filename: _combined.out\n";
#/usr/bin/perl-w
#文件:combine_all.pl
#说明:此程序将合并当前目录中所有“gff”文件的费率。
使用化学武器#提供与当前工作目录相关的功能
我的(@handles);
打印“进程正在启动…请稍候这可能需要几分钟…\n”;
取消链接“_combined.out”#这将删除文件(如果存在)
for(){
@file=split(“\”,$\);
推送(@files,substr($file[0],2));
打开($handles[@handles],$);
}
打开(输出文件“>”合并输出“);
foreach(@files){
打印输出文件“$\”\t”;
}
#打印输出文件“\n”;
我的$continue=1;
而(续){
$continue=0;
对于我的$op(@handles){
如果($ux=readline($op)){
my@col=分割;
如果($col[8]){
$gibberish=0;
$col[3]+=0;
$key=$col[3];
$col[5]+=0;#否则不打印任何内容
$col[5]=sprintf(“%.2f”,$col[5]);
打印输出文件“$col[5]\t”;
$continue=1;
}否则{
$key=“\t”;
$continue=1;
$gibberish=1;
}
}否则{
#无所事事
}
}
如果($continue!=0&&$gibberish!=1){
打印输出文件“$key\n”;
}否则{
打印输出文件“\n”;
}
}
undef@handles; #关闭所有文件
关闭(输出文件);
打印“进程完成!输出文件位于当前目录中,文件名为:\ u combined.out\n”;

我正在考虑使用此实用程序,但注意到它用于合并两个文件,而不是文件夹中的所有文件。我不知道如何在不编写好的代码使其正常工作的情况下利用这个工具。