免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1900 | 回复: 1
打印 上一主题 下一主题

文件有部分重复,求大侠们帮忙 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2017-05-23 23:16 |只看该作者 |倒序浏览
fileA:
X    1    A    1
N    1    A    1-2
X    1    B    1-2
X    2    C    2

fileB:
2    20    b    Y
2    20    b    X
1    10    a    Y
1    10    b    Y
1    20    a    Y
3    30    c    Y

自己有类似上边的两个文件,想根据黄色标记的ID合并两个文件然后提取指定的列,仍然按照fileA的顺序。如果提取ID对应的值一样就一行输出,不一样就分多行输出。
一些ID有重复,对应的值也不一样啊啊,不知道怎么办才好了,求大侠们帮帮忙

1    A    1    10    a
1    A    1    10    b
1    A    1    20    a
1    A   1-2   10    a
1    A   1-2   10    b
1    A   1-2   20    a
1    B   1-2   10    a
1    B   1-2   10    b
1    B   1-2   20    a
2    C    2    20     b


论坛徽章:
0
2 [报告]
发表于 2017-05-24 11:56 |只看该作者

  1. #!/usr/bin/perl
  2. use 5.010;

  3. @ARGV = qw/fileA fileB/;
  4. my $String_fileA = shift;
  5. my ( %Hash_key_string_value_array_of_string_fileB,
  6.     %Hash_key_string_value_hashref_key_string_value_hashref_key_string_value_int_fileBFilter
  7. );

  8. while (<>) {
  9.     my ( $String_one, $String_two, $String_three ) = split;
  10.     push @{ $Hash_key_string_value_array_of_string_fileB{$String_one} },
  11.       join "\t", $String_two, $String_three
  12.       unless
  13.       $Hash_key_string_value_hashref_key_string_value_hashref_key_string_value_int_fileBFilter{
  14.         $String_one}{$String_two}{$String_three}++;

  15. }

  16. @ARGV = $String_fileA;
  17. while (<>) {
  18.     chomp;
  19.     my ( undef, $String_two, $String_three, $String_four ) =
  20.       split /\s+/;

  21.     next unless $Hash_key_string_value_array_of_string_fileB{$String_two};

  22.     for ( @{ $Hash_key_string_value_array_of_string_fileB{$String_two} } ) {
  23.         say $String_two, "\t", $String_three, "\t", $String_four, "\t", $_;
  24.     }
  25. }

复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP