2つのリストがあり、最初のリストにはすべての名前が含まれています。
$ cat file1.txt
dog_02
dog_01
dog_20
dog_22
dog_23
dog_24
私の2番目のリストには最初のリストの名前があります。
$ cat file2.txt
dog_01
dog_23
dog_24
両方のリストをペアリングしてブール出力を取得したいと思います。
dog_02
dog_01 dog_01
dog_20
dog_22
dog_23 dog_23
dog_24 dog_24
if (空) {print "0"} else {print "1"} ;Complete> boolean_output.txt
$ cat boolean_output.txt
dog_02 0
dog_01 1
dog_20 0
dog_22 0
dog_23 1
dog_24 1
時間をいただきありがとうございます
ベストアンサー1
awk
解決策:
awk 'NR==FNR{ a[$1]; next }{ printf "%s\t%d\n",$1,($1 in a) }' file2.txt file1.txt > boolean_output.txt
{ a[$1]; next }
- 最初の入力ファイルのすべての値をキャプチャします。file2.txt
($1 in a)
- マッチングキー条件の確認名前2番目の入力ファイルを処理するときfile1.txt
最終boolean_output.txt
コンテンツ:
dog_02 0
dog_01 1
dog_20 0
dog_22 0
dog_23 1
dog_24 1