When you iterate over the same file twice you can use line numbers as convenient indices; it can make for cleaner logic.

    awk 'NR == FNR {if ($2 in z) { y[z[$2]]; y[FNR] } z[$2]=FNR; next} (FNR in y)' file file

I used a similar trick in my answer to this question:

- https://unix.stackexchange.com/q/320920/135943

---

The basis of this trick is that Awk will create a variable simply by referencing it, and the `index in arrayname` construct returns true or false depending on whether an array element has been created with the specified index.