0

I have two file like this

FILE 1

aaaaa  6578
vvvvv  6784
hhhhh  8905
fffff  3245
bbbbb  9876

FILE 2

hhhhh
bbbbb

I would like an output in which there are only the rows of FILE 2 with the relative information present in FILE 1.

Ex. OUTPUT

hhhhhh 8905
bbbbbb 9876

Can you help me?

Thanks

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
  • Possibly related: [How to filter out lines of a command output that occur in a text file?](https://unix.stackexchange.com/questions/299462/how-to-filter-out-lines-of-a-command-output-that-occur-in-a-text-file). – Paulo Tomé Feb 05 '20 at 10:02

3 Answers3

0

The information in FILE 1 are in 2 different columns, the first with all name (aaaaa, vvvvv, etc.) and the second with the numerical information.

Kevdog777
  • 3,194
  • 18
  • 43
  • 64
0

Try with grep,

grep -f file2 file1
hhhhh  8905
bbbbb  9876
  • -f Obtain patterns from FILE.
Siva
  • 9,017
  • 8
  • 56
  • 86
0

With awk:

awk 'NR==FNR{ a[$0]; next } $1 in a' file2 file1

When file2 is read, save each line in array a.
When file1 is read, print the current line if the first field is present in array a.

Freddy
  • 25,172
  • 1
  • 21
  • 60