0

両方のファイルに入っている交差レコードを見つけたいです。制限は、ファイル内の任意の位置にレコードを表示できることです。そのために私は以下のコードを使用しています

awk 'FNR==NR{a[$0];next}($0 in a)' 1.txt 2.txt

しかし、それは正しく機能していません。

1.txt と 2.txt という 2 つのファイルがあるとします。

1.txt

A
B
D
E

2.txt

DD
T
B
A
Z

出力は次のようになります

B
A

これについて私を助けてください。

4

2 に答える 2

1

これを試してください:

grep -w -f 1.txt 2.txt

-w 単語の状態

-f ファイルの状態

于 2013-02-08T11:57:57.643 に答える
0

別のオプション:

コマンドを使用しますcomm。それがこのコマンドの目的です。

comm <(sort 1.txt)  <( sort 2.txt) -12

からman comm:

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)

ただし、commソートされたファイルが必要です。したがって、<(sort 1.txt)&としてのプロセス置換<(sort 2.txt)

于 2013-02-08T12:55:29.160 に答える