12

長いがソートされたファイルが 2 つあります。2番目のファイルにない最初のファイルのすべての行を取得する方法は?

ファイル1

0000_aaa_b
0001_bccc_b
0002_bcc <------ file2 have not that line
0003_aaa_d
0006_xxx
...

ファイル2

0000_aaa_b
0001_bccc_b
0003_aaa_d
0006_xxx
...
4

2 に答える 2

17

commコマンドの目的は次のとおりです。

$ comm -3 file1 file2
0002_bcc

からman comm:

DESCRIPTION

   Compare sorted files FILE1 and FILE2 line by line.

   With  no  options,  produce  three-column  output.  Column one contains
   lines unique to FILE1, column two contains lines unique to  FILE2,  and
   column three contains lines common to both files.

   -1     suppress column 1 (lines unique to FILE1)

   -2     suppress column 2 (lines unique to FILE2)

   -3     suppress column 3 (lines that appear in both files)
于 2013-10-05T18:12:47.923 に答える
3

それらに対して a を実行するだけdiffです:

diff -c file1 file2

( -c"context" の) フラグは、異なる行のみを表示し、各行を 2 つの行で囲みます。

于 2013-10-05T18:10:28.737 に答える