亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 求助,怎樣多個文件對比合并出結(jié)果? [打印本頁]

作者: lockeyou    時間: 2016-08-18 14:46
標(biāo)題: 求助,怎樣多個文件對比合并出結(jié)果?
本帖最后由 lockeyou 于 2016-08-18 14:47 編輯

txt1
13288888888,1
13288888889,7

txt2
13288888888,200
13288888890,5000

txt3
xa,1,張三,男,13288888888,0,0,0,0,,,,
sh,2,李四,男,13288888889,0,0,0,0,,,,
sh,3,王五,女,13288888890,0,0,0,0,,,,
bj,4,毛六,男,13288888891,0,0,0,0,,,,

txt4
xa,1,張三,男,13288888888,1,0,200,0,,,,
sh,2,李四,男,13288888889,7,0,0,0,,,,
sh,3,王五,女,13288888890,0,0,5000,0,,,,
bj,4,毛六,男,13288888891,0,0,0,0,,,,

PS:txt4就是想要的答案
另想請教一下大牛在linux環(huán)境下對excel某幾個單元格修改有沒有方法,tks
原因,原本是根據(jù)sql求出值寫到excel里,但是excel修改單元格貌似只有在win下才可以用,后決定先把結(jié)果寫到txt里面進行操作,操作完成后再創(chuàng)建對應(yīng)excel進行展示。

作者: stanley_tam    時間: 2016-08-18 14:46
這樣?
  1. #!perl
  2. use strict;

  3. open my $fh1, '<', 'txt1';
  4. my $data_href = +{};
  5. while (defined (my $line = readline $fh1)) {
  6.     chomp $line;
  7.     my ($phone_number, $times) = split /,/, $line;
  8.     $data_href->{$phone_number}->{'times'} = $times;
  9. }
  10. close $fh1;

  11. open my $fh2, '<', 'txt2';
  12. while (defined (my $line = readline $fh2)) {
  13.     chomp $line;
  14.     my ($phone_number, $score) = split /,/, $line;
  15.     $data_href->{$phone_number}->{'score'} = $score;
  16. }
  17. close $fh2;

  18. open my $fh3, '<', 'txt3';
  19. open my $fh4, '>', 'txt4';
  20. while (defined (my $line = readline $fh3)) {
  21.     chomp $line;
  22.     my @parts = split /,/, $line, 13;
  23.     my $phone_number = $parts[4];

  24.     $parts[5] = $data_href->{$phone_number}->{'times'} || 0;
  25.     $parts[7] = $data_href->{$phone_number}->{'score'} || 0;

  26.     my $new_line = join ',', @parts;
  27.     print {$fh4} "$new_line$/";
  28. }
  29. close $fh3;
  30. close $fh4;


  31. __END__
復(fù)制代碼

作者: sunzhiguolu    時間: 2016-08-18 20:01
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;

  4. my ($first, %hData) = "";
  5. while (<>){
  6.     chomp;
  7.     my @aList = split (/,/, $_, -1);
  8.     if (@ARGV){
  9.         $first = $ARGV if ($first eq "");
  10.         my @aT = ($aList[-1], 0);
  11.         if ($first eq $ARGV){
  12.             push (@{$hData{$aList[0]}}, @aT);
  13.         }else{
  14.             my $has = exists $hData{$aList[0]};
  15.             push (@{$hData{$aList[0]}}, $has ? @aT : (0, 0, @aT));
  16.         }
  17.         next;
  18.     }
  19.     if (exists $hData{$aList[4]}){
  20.         my @aT = @{$hData{$aList[4]}};
  21.         @aList[5 .. 8] = @aT > 2 ? @aT : (@aT, 0, 0);
  22.     }
  23.     print join (",", @aList), "\n";
  24. }
復(fù)制代碼
perl abc.pl a b c
-------------------------------------------------------------------
xa,1,張三,男,13288888888,1,0,200,0,,,,
sh,2,李四,男,13288888889,7,0,0,0,,,,
sh,3,王五,女,13288888890,0,0,5000,0,,,,
bj,4,毛六,男,13288888891,0,0,0,0,,,,

作者: sunzhiguolu    時間: 2016-08-18 20:23
如果不是以編程的方式修改 MS Excel 單元格內(nèi)容的話, 可以使用 LibreOffice 辦公套件. 開源, 跨平臺.
作者: MMMIX    時間: 2016-08-18 23:42

  1. #!/usr/bin/perl

  2. use strict;
  3. use warnings;

  4. use v5.16;
  5. use autodie;
  6. use Data::Dumper;

  7. sub load_data1 {
  8.   local @ARGV = @_;

  9.   my %records;
  10.   while (<>) {
  11.     chomp;
  12.     my ($k, $v) = split /\s*,\s*/;
  13.     $records{$k} = $v;
  14.   }

  15.   return wantarray ? %records : \%records;
  16. }

  17. sub load_data2 {
  18.   local @ARGV = @_;

  19.   my @records;
  20.   while (<>) {
  21.     chomp;
  22.     push @records, [split /\s*,\s*/, $_, -1];
  23.   }

  24.   return wantarray ? @records : \@records;
  25. }

  26. ###

  27. die "Usage: $0 txt1 txt2 txt3" unless @ARGV >= 3;

  28. my $records1 = load_data1 $ARGV[0];
  29. my $records2 = load_data1 $ARGV[1];
  30. my $records3 = load_data2 $ARGV[2];

  31. foreach (@$records3) {
  32.   my $id = $_->[4];
  33.   $_->[5] = $records1->{$id} if exists $records1->{$id};
  34.   $_->[7] = $records2->{$id} if exists $records2->{$id};

  35.   say join(',', @$_);
  36. }
復(fù)制代碼

作者: lockeyou    時間: 2016-08-22 08:45
謝謝樓上各位大神的解決方案,好久沒寫代碼,都忘了sub了,哈哈




歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2