1

My example goes like that:

 FILE_A
 ABC   spring    14    60  
 FILE_B
 ABC 

I want to print FILE_A if first column matches FILE_B first column && second column is "spring".

awk 'NR==FNR {a[$1]=$1;next} ; {if ($4=="spring" && $5 in a) {print $0}' FILE_B FILE_A    

This works fine, but if I want to add condition if 60-(14-60)>0 I can't get it.

I tried if ($4=="spring" && $4-($3-$4)>0 && $5 in a), but I can't get it work.

My question is:
How to make awk if conditions with "in an array" condition?

0

1 Answer 1

2

You're not using the right field numbers and leaving your boolean logic ambiguous, just use the correct field numbers and paranthesise:

awk 'NR==FNR {a[$1];next} ($1 in a) && ($2=="spring") && (($4-($3-$4))>0)' FILE_B FILE_A

Obviously $4-($3-$4) can be reduced!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.