Given:
$ cat file1
001 word1
002 word2
00n wordn1
$ cat file2
001 word3
002 word4
003 word_u1
004 word_u2
00n wordn2
(Note the extra 003 word_u1
and 004 word_u2
in file2...)
You can use join
that joins those files (as presented) together:
$ join file1 file2
001 word1 word3
002 word2 word4
00n wordn1 wordn2
If the files are not sorted (as you have presented them) you can sort first:
$ join <(sort file1) <(sort file2)
If you want to double up the digits, pipe to sed:
$ join file1 file2 | sed -nE 's/^([^[:space:]]*)/1 1/p'
001 001 word1 word3
002 002 word2 word4
00n 00n wordn1 wordn2
Or specify the join
output list:
$ join -o 1.1,2.1,1.2,2.2 file1 file2
001 001 word1 word3
002 002 word2 word4
00n 00n wordn1 wordn2
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…