grep in two files returning two columns

511 Views Asked by At

I have a big file like this:

79597700
79000364
79002794
79002947

And other big file like this:

79597708|11
79000364|12
79002794|11
79002947|12
79002940|12

Then i need the numbers that appear in the second file that are in the first file bur with the second column, something like:

79000364|12
79002794|11
79002947|12
79002940|12

(The MSISDN that appear in the first file and appear in the second file, but i need return the two columns of the second file)

Who can help me, because whit a grep does not work to me because return only the MSISDN without the second column and with a comm is not possible because each row is different in the files

2

There are 2 best solutions below

0
On

Using awk:

awk -F"|" 'FNR==NR{f[$0];next}($1 in f)' file file2

Source: return common fields in two files

6
On

Try this:

grep -f bigfile1 bigfile2