I have two files which I would like to compare. If string exists in file 1 (which only has one column), I would like to print a 2 next to it. If it only exists in file 2, I would like to print a 1 next to it. I want to keep all entries of file 2.
File 1:
5131885
5751191
File 2:
5131885 1000019 -0.013936 0.0069218 -0.0048443 -0.0053688 0.0074161
5751191 1000046 -0.015001 0.0015263 0.00039903 0.0017072 -0.0021732
1668460 1000081 0.026323 0.0068929 0.0048965 0.0077047 0.0061728
File 3 (desired output):
5131885 2 1000019 -0.013936 0.0069218 -0.0048443 -0.0053688 0.0074161
5751191 2 1000046 -0.015001 0.0015263 0.00039903 0.0017072 -0.0021732
1668460 1 1000081 0.026323 0.0068929 0.0048965 0.0077047 0.0061728
I tried to do it with awk, but I was not successful. I reached this point:
awk 'FNR==NR{arr[$1]=$1;next} ($1 in arr){print $0,arr[$1]}' file2 file1 > file3
But it does not add an extra column.