I have two tab separated files (please see the examples below):
File 1
Java RAJ
PERL ALEX
PYTHON MAurice
(and so on)
File 2
ALEX 3.4
SAM 8.9
PEPPER 9.0
Now, if for instance say ALEX is also found in file 2 (it is not for sure that ALEX will be found) I should have a third file looking like this:
PERL ALEX 3.4
The code should check for all the values in column 2 of file 1 in file2.
Any suggestions for a bash script?
You received excellent answers using join and awk, so I thought I's post a pure bash-one:
outputs:
You want to use
join
for that. First you need to sort according to join field though:Is a one-liner with PERL also ok? Works without sorting.. Assuming your files are called f1 and f2..
With f1:
And f2:
Results in: