Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to merge two file with awk?

Tags:

awk

I have two files which are in same order and they have the same number of rows:

file1(only 2 columns):

562_201 RIR1
562_202 RIR1
562_203 RIR1
562_204 RIR1
562_205 RIR1
562_206 RIR1
562_207 RIR1
562_208 RIR1
562_209 RIR1
562_210 WR1 
562_211 WR1 
562_212 WR1 

file2 (I should say that file2 has more than million rows!):

562_201 0101
562_202 0101
562_203 0101
562_204 0101
562_205 0101
562_206 0101
562_207 0101
562_208 0101
562_209 0101
562_210 0101
562_211 0101
562_212 0101

and I want to merge them to get:

562_201 RIR1 0101
562_202 RIR1 0101
562_203 RIR1 0101
562_204 RIR1 0101
562_205 RIR1 0101
562_206 RIR1 0101
562_207 RIR1 0101
562_208 RIR1 0101
562_209 RIR1 0101
562_210 WR1  0101
562_211 WR1  0101
562_212 WR1  0101

thanks!

like image 283
mahmood Avatar asked Nov 28 '22 17:11

mahmood


1 Answers

You can use join command:

$ join file1.txt file2.txt
like image 51
kev Avatar answered Dec 04 '22 04:12

kev