awk は 2 つのファイル間の値と一致します。

awk は 2 つのファイル間の値と一致します。

両方のファイルの最初の列を比較したいです。一致するものがあれば、2 番目のファイルの対応する値が 1 番目のファイルにエクスポートされます。

File 1
username, fields

File 2
username, other_fields

Output File
username, fields, other_field if there is a match else blank

このコードを使用しましたが、出力ファイルは空です。

awk 'NR==FNR { a[$1]=$2; next} $1 in a {print $0, a[$1]}' File2 File1

ベストアンサー1

使用join:

join -t, -a1 <(sort -k1,1 -t, file1) <(sort -k1,1 -t, file2)

またはcsvjoincsvkit:

csvjoin --left -H -c a file1 file2

おすすめ記事