I'm new to AWK and I'm having problems comparing a field to a string variable.
/ARTIST/ {x = $2}
$1 ~ x {print $0}
My code tries to find a record with the string "ARTIST". Once it finds it, it stores the second field of the record into a variable. I don't know what the problem is for the second line. The point is if the first field of a record matches the variable, it will print the entire record. But for some reason, it's not working.
For example, I want to go through the second file, so I'll store "John" into variable x. Then I want to compare x to the first fields of the first file. If it equals, then I'll print out the entire record. I'm having trouble making that comparison for the variable and the field.
Yes, "x" is an associative array, with "John" and "Bob" as its keys. $1 in x is true when 1st field of file1 is among the keys of array "x" (so this is how it is being searched).