Comparing column from two different files

I have two files with different size and formal and want to compare all the values of one of the column in file 1 compared with values of one of the column in file 2 and return the common values as output file.

can someone please help if the file size and format are same i am able to get output but not if the files are not same.

file 1

values  name                                  
100        A                                          
300        B                                         
200        C                   
400        D                   

file 2

name     values
  D           400
  B           300
  E           600 
  H           500

output (common values in file1 and file 2 based on column(values)

name     values
 B           300
 D           400
 awk 'NR==FNR {T[$2,$1]; next} $1","$2 in T' SUBSEP="," file1 file2
name     values
  D           400
  B           300

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

There is no need to change SUBSEP if you use parentheses:

awk 'NR==FNR {T[$2,$1]; next} ($1,$2) in T' file1 file2
1 Like

Brilliant. That I didn't try. I parenthesized every man and his dog, but that escaped me.