0

I have the following files:

a.txt

1
2
11
22
33
444

b.txt

1
2
3
11
22
33
555

I want to retrieve the lines from a.txt that do not exists on b.txt.

I tried with that:

diff a.txt b.txt -d
2a3
> 3
6c7
< 444
---
> 555

But I want the output to be

444

Only. Is there a way to place some sort of filters upon diff?

2 Answers 2

1

It would be better to use grep

grep -f b.txt -v a.txt

Key -f will define b.txt as list of patterns to search in a.txt. And key -v will reverse the search and printout line from a.txt where the pattern was not found.

1

diff might be the wrong tool, use grep instead:

grep -vxf b.txt a.txt

i.e. get any line from a.txt not present in b.txt

Alternatively, comm would work by suppressing lines in both and the second file:

comm -23 <(sort a.txt) <(sort b.txt)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .