unix - AWK Compare 2 columns in 2 files, print if one is equal while other is not -
i trying print lines file 1 + column 3 file 2 if column 1 in both files matches column 3 doesnt match.
example:
file1 john 12 mango david 13 apple jack 14 orange file2 john 12 grape david 13 apple jack 14 apple output
john 12 mango grape jack 14 orange apple i tried different awk commands work when both column matches need print when 1 column match , other doesn't. new script , unix command, appreciate little explanation of proposed solution.
$ awk 'nr==fnr{a[$1]=$3; next} ($1 in a) && (a[$1] != $3){print $0, a[$1]}' file2 file1 john 12 mango grape jack 14 orange apple
Comments
Post a Comment