L.Jovi
L.Jovi

Reputation: 1761

check difference via minus between two file

I have two files test1 and test2

test1

foo
bar
hello
world

test2

bar
world
hello

and I really want to obtain foo here, could anybody help me? please ..

Upvotes: 1

Views: 54

Answers (3)

Kruncho
Kruncho

Reputation: 205

If you have vim installed, you can use :

vimdiff test1 test2

But it's just to edit files. If you only just want foo appears on the screen it's not what you want

Upvotes: 0

NeronLeVelu
NeronLeVelu

Reputation: 10039

if not GNU grep

cat test1 test2 test2 | sort | uniq -u

Upvotes: 0

John1024
John1024

Reputation: 113994

To print all the lines in test1 which are not also in test2, run:

$ grep -vFf test2 test1
foo

How it works

The options to grep have the following meanings:

  • -v

    Print only lines that do not match any of the patterns.

  • -F

    Interpret the patterns as fixed strings, not regex.

  • -f test2

    Read the patterns from test2.

Upvotes: 6

Related Questions