I am trying join two files by one common column (1) between two file (File1 and file2), resulting in file 3, but the resultant file is not working. Can someone help me?I used this command: awk 'NR==FNR {h[$1] = $0; next} {print h[$1],$0}' file1 file2 > file3File 1.1 1767 0 1986 28061997 1 1 1 0 29031998 972 34176 9 1 9 9 55 97 42 1 02 1876 0 1986 25051995 1 1 1 0 22072000 952 30438 1 1 3 9 1009 95 25 4 03 5878 0 1986 16071996 1 1 1 0 22071997 963 30438 4 1 3 9 1009 96 40 4 0File 2: 1 0 5 8 25031998 2 11 1071997 943 11 1101997 944 11 1011998 951 18 1011998 95 BX1001337 AX54651 BR909511 02 0 53 8 19021996 2 8 22031996 6 8 27051996 1 14 27051996 2 7 27051996 2 15 27051996 2 8 21021997 2 8 22031997 6 8 20041997 1 14 20041997 3 15 20041997 3 8 22071997 6 8 28091998 1 14 28091998 4 15 28091998 4 8 25061999  2 8 22091999 6 8 7032000 1 14 7032000 5 15 7032000 3 16 7032000 1 11 1071995     923 11 1101995 924 11 1011996 931 18 1011996 93 11 1041996 932 11 1071996 933 11 1101996 934 11 1011997 941 18 1011997 94 11 1041997 942 11 1071997 943 11 1101997 944 11 1011998 951 18 1011998 95 11 1041998 952 17 1041998 1005 11 1071998 953 17 1071998 1007 11 1101998 954 11 1011999 961 18 1011999 96 11 1041999 962 17 1041999 1009 11 1071999 963 17 1071999 1007 11 1101999 964 17 1101999 1003 11 1012000 971 18 1012000 97 17 1012000 1005 11 1042000 972 11 1072000 973 BR1001881 AX62116 BR872756 03 0 6 8 12041997 2 11 1101996 934 11 1011997 941 18 1011997 94 11 1041997 942 11 1071997 943 BR1003576 AX52602 BR830819 0File3. Its working wrong.Is putting the file 2 in 2 line..1 1767 0 1986 28061997 1 1 1 0 29031998 972 34176 9 1 9 9 55 97 42 1 01 1 0 5 8 25031998 2 11 1071997 943 11 1101997 944 11 1011998 951 18 1011998 95 BR1001337 AX54651 BR909511 02 1876 0 1986 25051995 1 1 1 0 22072000 952 30438 1 1 3 9 1009 95 25 4 02 4 0 53 8 19021996 2 8 22031996 6 8 27051996 1 14 27051996 2 7 27051996 2 15 27051996 2 8 21021997 2 8 22031997 6 8 20041997 1 14 20041997 3 15 20041997 3 8 22071997 6 8 28091998 1 14 28091998 4 15 28091998 4 8 25061999  2 8 22091999 6 8 7032000 1 14 7032000 5 15 7032000 3 16 7032000 1 11 1071995     923 11 1101995 924 11 1011996 931 18 1011996 93 11 1041996 932 11 1071996 933 11 1101996 934 11 1011997 941 18 1011997 94 11 1041997 942 11 1071997 943 11 1101997 944 11 1011998 951 18 1011998 95 11 1041998 952 17 1041998 1005 11 1071998 953 17 1071998 1007 11 1101998 954 11 1011999 961 18     1011999 96 11 1041999 962 17 1041999 1009 11 1071999 963 17 1071999 1007 11 1101999 964 17 1101999 1003 11 1012000 971 18 1012000 97 17 1012000 1005 11 1042000 972 11 1072000 973 BR1001881 AX62116 BR872756 03 5878 0 1986 16071996 1 1 1 0 22071997 963 30438 4 1 3 9 1009 96 40 4 03 4 0 6 8 12041997 2 11 1101996 934 11 1011997 941 18 1011997 94 11 1041997 942 11 1071997 943 BR1003576 AX52602 BR830819 0File3. I would like that:1 1767 0 1986 28061997 1 1 1 0 29031998 972 34176 9 1 9 9 55 97 42 1 0 0 5 8 25031998 2 11 1071997 943 11 1101997 944 11 1011998 951 18 1011998 95 BR1001337 AX54651 BR909511 02 1876 0 1986 25051995 1 1 1 0 22072000 952 30438 1 1 3 9 1009 95 25 4 0 0 53 8 19021996 2 8 22031996 6 8 27051996 1 14 27051996 2 7 27051996 2 15 27051996 2 8 21021997 2 8 22031997 6 8 20041997 1 14 20041997 3 15 20041997 3 8 22071997 6 8 28091998 1 14 28091998 4 15 28091998 4 8 25061999 2 8 22091999 6 8 7032000 1 14 7032000 5 15 7032000 3 16 7032000 1 11 1071995 923   11 1101995 924 11 1011996 931 18 1011996 93 11 1041996 932 11 1071996 933 11 1101996 934 11 1011997 941 18 1011997 94 11 1041997 942 11 1071997 943 11 1101997 944 11 1011998 951 18 1011998 95 11 1041998 952 17 1041998 1005 11 1071998 953 17 1071998 1007 11 1101998 954 11 1011999 961 18 1011999 96 11 1041999 962 17 1041999 1009 11 1071999 963 17 1071999 1007 11 1101999 964 17 1101999 1003 11 1012000 971 18 1012000 97 17 1012000 1005 11 1042000 972 11 1072000 973 BR1001881 AX62116 BR872756 03 5878 0 1986 16071996 1 1 1 0 22071997 963 30438 4 1 3 9 1009 96 40 4 0 0 6 8 12041997 2 11 1101996 934 11 1011997 941 18 1011997 94 11 1041997 942 11 1071997 943 BR1003576 AX52602 BR830819 0
How join two files by one common column (1) between two file (File1 and file2)?
awk;join
Try this one liner!.awk 'FNR==NR{A[$1]=$0;next}{line=;for(i=2;i<=NF;i++)line=line $i ;sub( $,,line);if ($1 in A)print A[$1] line;}' file1.txt file2.txt > file3Out1 1767 0 1986 28061997 1 1 1 0 29031998 972 34176 9 1 9 9 55 97 42 1 0 0 5 8 25031998 2 11 1071997 943 11 1101997 944 11 1011998 951 18 1011998 95 BX1001337 AX54651 BR909511 02 1876 0 1986 25051995 1 1 1 0 22072000 952 30438 1 1 3 9 1009 95 25 4 0 0 53 8 19021996 2 8 22031996 6 8 27051996 1 14 27051996 2 7 27051996 2 15 27051996 2 8 21021997 2 8 22031997 6 8 20041997 1 14 20041997 3 15 20041997  3 8 22071997 6 8 28091998 1 14 28091998 4 15 28091998 4 8 25061999 2 8 22091999 6 8 7032000 1 14 7032000 5 15 7032000 3 16 7032000 1 11 1071995 923 11 1101995 924 11 1011996 931 18 1011996 93 11 1041996 932 11 1071996 933 11 1101996 934 11 1011997 941 18 1011997 94 11 1041997 942 11 1071997 943 11 1101997 944 11 1011998 951 18 1011998 95 11 1041998 952 17 1041998 1005 11 1071998 953 17 1071998 1007 11 1101998 954 11 1011999 961 18 1011999 96 11 1041999 962 17 1041999 1009 11 1071999 963 17 1071999 1007 11 1101999 964 17 1101999 1003 11 1012000 971 18 1012000 97 17 1012000 1005 11 1042000 972 11 1072000 973 BR1001881 AX62116 BR872756 03 5878 0 1986 16071996 1 1 1 0 22071997 963 30438 4 1 3 9 1009 96 40 4 0 0 6 8 12041997 2 11 1101996 934 11 1011997 941 18 1011997 94 11 1041997 942 11 1071997 943 BR1003576 AX52602 BR830819 0Saves in A lines from file1 by first column, starts reading file2, skips first column and saves fields in line, if first column in A concatenates both lines in one line and prints.