awk — Joins & Lookups
Inner join on first column — only matching keys
awk 'NR==FNR {a[$1]=$2; next} $1 in a {print $0, a[$1]}' file1 file2
Left join — keep all from second file, NULL for missing
awk 'NR==FNR {a[$1]=$2; next} {print $0, ($1 in a ? a[$1] : "NULL")}' file1 file2
Enrich log with hostname lookup
awk 'NR==FNR {ip[$1]=$2; next} {print $0, "(" ip[$4] ")"}' hosts_lookup.txt access.log
Load lookup from external file via getline in BEGIN
awk 'BEGIN{while((getline line < "lookup.txt") > 0){split(line,a); map[a[1]]=a[2]}} {if($1 in map) print $0, map[$1]}' data.txt
Merge two sorted files by shared key
awk 'NR==FNR {val[$1]=$2; next} ($1 in val) {print $0, val[$1]}' lookup.txt main.txt