I am using Win7 with Cygwin. I have a one-liner that will work for identifying matches in a PAIR of columns, but when I try to introduce additional columns (i.e. >2) I cannot get it to work. So the following works for me:
gawk -F "^" '{ if ($3 == $7) print "0"; else print $3,$7; }' infile.txt > outfile.txt
However when I add in another pair of columns I get syntax errors:
gawk -F "^" '{ if ($3 == $7 || $3 == $11) print "0"; else print $3,$7,$11; }' infile.txt > outfile.txt
So something is wrong with the command, but the error messages are not really helpful to me. When I substitute "&&" for "||" I also get errors ("unexpected newline or end of string" straight after the first "$7" and also "$3 is not recognised as an internal or external command, operable program or batch file").
So here's an example input file, containing the three rows, with "^" as column delimiter:
paris^london^new york^paris^rome^paris
paris^london^munich^paris^rome^paris
paris^london^munich^berlin^rome^paris
I want to be able to see if, in each row of the file, columns 1, 4, and 6 match each other. So in this case, row 1 is "yes", row 2 is "yes" and row 3 is "no". So the output should show either "0" for "yes" or repeat the whole row for "no". So output would be:
0
0
paris^london^munich^berlin^rome^paris
Any ideas ?
$1 == $4 && $1 == $6
gawk -F "^" -f scr_file input_file > output_file
. See if that works