Find lines from a file which are not present in another file [duplicate] Ask Question

Find lines from a file which are not present in another file [duplicate] Ask Question

I have two files (let's say a.txt and b.txt), both of which has a list of names. I have already run sort on both the files.

Now I want to find lines from a.txt which are not present in b.txt.

(I spent lot of time to find the answer for this question, so documenting it for future reference)

ベストアンサー1

使用すべきコマンドはdiffcomm

/usr/bin/comm -23 a.txt b.txt

デフォルトでは、comm3 つの列を出力します。左のみ右のみ両方-1、およびスイッチ-2-3これらの列を抑制します。

-23だから、右のみそして両方列には、最初の (左側の) ファイルにのみ表示される行が表示されます。

両方に現れる行を見つけたい場合は、 を使用します-12左のみそして右のみ列が表示され、両方カラム。

おすすめ記事