You can square-off your position anytime before expiry. The difference between the price at which you buy/sell at and square-off at will be your P&L.
If you don’t square-off your position, then upon expiry, if the position is ITM, it’ll be settled by the exchange at intrinsic value and if the position is OTM, it’ll expire worthless.
Index Options are cash settled, so you don’t have to give or take delivery of underlying. You can refer to this post for more information: What happens if I don't square off my positions in options? - #2 by ShubhS9