0

任意の数のファイルから最初の列を抽出し、欠落しているエントリのために空の行で列を出力する必要があります。空行部分に問題があります。そのようです:

File1:
Alfa        Something    More stuff
Charlie     Something    More stuff
Delta       Something    More stuff
Echo        Something    More stuff
Foxtrot     Something    More stuff

File2:
Alfa        Something    More stuff
Bravo       Something    More stuff
Echo        Something    More stuff
Foxtrot     Something    More stuff

File3:
Alfa        Something    More stuff
Bravo       Something    More stuff
Charlie     Something    More stuff
Delta       Something    More stuff
Echo        Something    More stuff

Output:
FileName1    FileName2    FileName3
=========    =========    =========
Alfa         Alfa         Alfa
             Bravo        Bravo
Charlie                   Charlie
Delta                     Delta
Echo         Echo         Echo
Foxtrot      Foxtrot
4

1 に答える 1

1

いくつかのマイナーなフォーマットの問題を除いて、これを行う1つの方法を次に示します。

awk '
  { 
    exists[$1] = 1;
    files[$1,ARGIND] = 1;
  }
  END {
    for (i=1; i<ARGC; ++i) {
      printf("%-20s",ARGV[i])
    }
    printf("\n");
    for (i=1; i<ARGC; ++i) {
      printf("%-20s","=================")
    }
    printf("\n");
    for (name in exists) {
      for (i=1; i<ARGC; ++i) {
        if (files[name,i]) {
          printf("%-20s",name);
        }
        else {
          printf("%-20s","");
        }
      }
      printf("\n");
    }
  }
' file1 file2 file3
于 2012-08-14T01:47:25.270 に答える