0

I have two text files, one with the following content:

Brazil
China
USA

And another file with the following content:

Brazil  8   9   5   2
China   1   2   2   1
France  7   4   1   2
Italy   0   1   2   3
Spain   5   4   6   8
UK      8   5   4   1
USA     1   2   3   4

I would like to use some command that compares both files and returns

Brazil  8   9   5   2
China   1   2   2   1
USA     1   2   3   4

The command comm doesn't seem to work in cases like this. How could I solve it?

Edit: although this question is marked as duplicated, the solutions for the other question are not the same presented here.

  • `comm` compares files line by line. That doesn't sound at all like what you want. Look at `grep` and check the `-f` option. It's very simple. :) – lurker Dec 15 '15 at 17:13

1 Answers1

1

Suppose you have nation names in file 1 and names and numbers in file 2 then

grep -wFf 1 2

should do the trick.

Alberto Zaccagni
  • 30,779
  • 11
  • 72
  • 106