I need to find matches with the string in column 1 ($1) in file1.txt with the string in column 1 ($1) in file2.txt. Then I want to join the lines where there was a match in
awk 'BEGIN {
FS = OFS = "\t"
}
NR == FNR {
# while reading the 1st file
# store its records in the array f
f[$1] = $0
next
}
$1 in f {
# when match is found
# print all values
print f[$1], $0
}' file1 file2
If you don't mind the output being ordered by the first column then you can use this invocation of the join command:
join <(sort file1.txt) <(sort file2.txt) >out.txt