Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get lines of file1 which are not in file2

Tags:

linux

I have two long, but sorted files. How to get all lines of first file which are not in second file ?

file1

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

file2

0000_aaa_b
0001_bccc_b
0003_aaa_d
0006_xxx
...
like image 984
marioosh Avatar asked Oct 05 '13 18:10

marioosh


1 Answers

Just run a diff on them:

diff -c file1 file2

The -c (for "context") flag will only display the lines that are different, with two lines surrounding each line.

like image 82
Bucket Avatar answered Sep 21 '22 02:09

Bucket