从不同目录中具有相同名称的多个文件中剪切列并粘贴到一个文件中

Cut column from multiple files with the same name in different directories and paste into one

我有多个同名文件 (3pGtoA_freq.txt),但都位于不同的目录中。 每个文件如下所示:

pos 5pG>A
1   0.162421557770395
2   0.0989643268124281
3   0.0804131316857248
4   0.0616563298066399
5   0.0577551761714493
6   0.0582450832072617
7   0.0393129770992366
8   0.037037037037037
9   0.0301016419077404
10  0.0327510917030568
11  0.0301598837209302
12  0.0309050772626932
13  0.0262089331856774
14  0.0254612546125461
15  0.0226130653266332
16  0.0206971677559913
17  0.0181280059193489
18  0.0243993993993994
19  0.0181347150259067
20  0.0224429727740986
21  0.0175690211545357
22  0.0183916336098089
23  0.0196078431372549
24  0.0187983781791375
25  0.0173192771084337

我想从每个文件中剪切第 2 列并逐列粘贴到一个文件中

我试过了运行:

for s in results_Sample_*_hg19/results_MapDamage_Sample_*/results_Sample_*_bwa_LongSeed_sorted_hg19_noPCR/3pGtoA_freq.txt; do awk '{print }' $s >> /home/users/istolarek/aDNA/3pGtoA_all; done

但它没有将各列粘贴在一起。

我还想用“*”来命名每一列,这是唯一改变路径的字符串。

有什么帮助吗?

for i in $(find you_file_dir -name 3pGtoA_freq.txt);do awk '{print $2>>"NewFile"}' $i;完成

我会通过在 awk 中并行处理所有文件来做到这一点:

awk 'BEGIN{printf "pos ";
           for(i=1;i<ARGC;++i)
             printf "%-19s",gensub("^results_Sample_","",1,gensub("_hg19.*","",1,ARGV[i]));
           printf "\n";
           while(getline<ARGV[1]){
             printf "%-4s%-19s",,;
             for(i=2;i<ARGC;++i){
               getline<ARGV[i];
               printf "%-19s",}
             printf "\n"}}{exit}' \
results_Sample_*_hg19/results_MapDamage_Sample_*/results_Sample_*_bwa_LongSeed_sorted_hg19_noPCR/3pGtoA_freq.txt

如果你的awk没有gensub(我用的是cygwin),你可以去掉前四行(printf-printf); headers 在这种情况下不会打印。