Linked Questions

Popular Questions

I have the following files: f1.txt:

1 1  
1 2   
3 3   
3 4   
2 5  
2 6  

f2.txt:

1  
2   
3  

I want to sort f1.txt according to f2.txt first column match, expected output is below

1 1  
1 2   
2 5   
2 6  
3 3  
3 4  

I tried something like

awk '{if(NR==FNR) {a[$1]=$0} else {b[$1]=$0} for(i in b) print a[i]}' f2.txt f1.txt 

But the results I'm getting are not what I expected.

Appreciate if someone can help

Related Questions