I'm trying to compare two files using AWK, where if field2 of both files match, replace field1 of file1 with field1 of file2 and if there is no match just print the line of file1.
Thanks, i did try to solve it and did many searches here using keywords awk and compare. However, i kept screwing it up, am very confused at this point, and got nowhere and i really don't want to mess-up my 743,000 record database file, with something like:
FNR==NR { arr[$2]=$1; next}
$2 in arr { print arr[$1], $0 }
if (field1 of file2) == (field2 of file1) then
awk -F: 'FNR == NR {
{ f1[$2]=$1 $2
next;
}
if ($2 in f1) print f1[$1]$0; else print $0;}' ~/Desktop/file2.txt ~/Desktop/file1.txt > ~/Desktop/outputfile.txt