-1

I have two tables of string values, and the objetive is to make a new table that only keeps the matching values from both parent tables.

Example:

TABLE1

AX-18000257
AX-18000500
AX-18000816
AX-18000945
AX-18001189
AX-18001512
AX-18001524

TABLE2

AX-18000257
AX-18000512
AX-18000816
AX-18000947
AX-18001589
AX-18001525
AX-18001524

Expected output would be:

AX-18000257
AX-18000816
AX-18001189
AX-18001524
miken32
  • 42,008
  • 16
  • 111
  • 154
  • 1
    What are the rest of the columns in the table? You can use `join` to join two files on specific fields. – Andreas Louv Nov 30 '21 at 13:54
  • 2
    `grep -v -f file2 file1 >> file3` – David Ranieri Nov 30 '21 at 13:55
  • I can see you edited your question. Do you have two files of strings, where you need to keep all that are in both files? – Andreas Louv Nov 30 '21 at 13:57
  • @AndreasLouv I realize that I could make it easier just usinf cut -f2 from the original file so I work only with the columns I really need insted of the whole table. So now the question is simplified. I am looking for the join argument and its usage and see if it works with my example. It really helped!! – Paulo Alvarez Nov 30 '21 at 14:10
  • Does this answer your question? [Shell command to find lines common in two files](https://stackoverflow.com/questions/373810/shell-command-to-find-lines-common-in-two-files) – miken32 Nov 30 '21 at 16:10

1 Answers1

0

It could be done with both:

grep -v -f file2 file1 >> file3 #thanks David Ranieri

Or with:

join -1 1 -2 1 file1 file 2 > file3

Using join with get you a warning join: file 1 is not in sorted order join: file 2 is not in sorted order but the result is correct