You don't need to read the input file twice:
awk '
{ vals[$2] = vals[$2] $0 ORS }
END {
for (i in vals) {
if ( gsub(ORS,"&",vals[i]) == 3 ) {
printf "%s", vals[i]
}
}
}
' eq9_1.ndx
Note that the above will work even for input coming from a stream.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…