SBLGNT: Ἐν τῷ κόσμῳ ἦν, καὶ ὁ κόσμος δι’ αὐτοῦ ἐγένετο, καὶ ὁ κόσμος αὐτὸν οὐκ ἔγνω.
1) Ἐν τῷ κόσμῳ ἦν- ἦν is imperfect indicative active 3rd person singular. Translate here "he was"; some prefer "it."
Bengel's Gnomon of the NT: ἐν τῷ κόσμῷ ἦν, He was in the world) The evangelist adds this, lest any one should so understand the expression, coming into the world, as if the Light had not been previously in the world at all. Three times in this verse world is repeated; three times it is said of the human race, as in the previous verse, but not to the exclusion of the other creatures, at least in the first place.
2) καὶ ὁ κόσμος δι’ αὐτοῦ ἐγένετο, καὶ ὁ κόσμος αὐτὸν οὐκ ἔγνω.
The masculine pronoun αὐτόν, him, refers to the neuter term τὸ φῶς, the light, which proves that αὐτοῦ also must be taken as masculine. This grammatical anomaly arises from the fact that the apostle has now in view the light in so far as it had personally appeared in Jesus. This is, likewise, the reason why he substitutes the word ἔγνω knew, for κατέλαβε laid hold of (John 1:5), although the idea is fundamentally the same. One lays hold of a principle, one recognizes a person.