I have a file similar to the following :

x 0
1 x
1 1

and I am essentially trying to see if both fields are equal to one another or not for every row. But the problem is that this file contains x which can either hold the value of 0 or 1 -- but I am not sure how to set this in awk

I tried working with the following code that did not work, it only works if x is set to either 0 or 1, not both.

y=$(seq 1 2)
awk -v x="$y" '{ if ($1==$2) print "good" }' file

Please advise or let me know if any clarification is necessary, thank you.

share|improve this question

A scalar variable in awk can only hold a single variable. You'll have to do something like this:

if (
    ($1 == "x" && ($2 == 0 || $2 == 1)) ||
    ($2 == "x" && ($1 == 0 || $1 == 1)) ||
    $1 == $2
) print "good"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.