Yes, it can be done if you’re careful and follow these steps (with brake left mounted on bike, so that lever is higher than caliper):
1) start by removing the pads and wheel and carefully pulling the brake lever so that the pistons move outwards, but not too much (leave at least 5mm between them)
2) unscrew the hose from the lever. The fluid shouldn’t leak out from either end.
3) cut hose to desired length, making sure you hold it upright so fluid can’t drip out. fit nut, olive and insert
4) screw hose back into brake lever
5) remove lever reservoir top cap (change angle of lever so that reservoir is horizontal to ground, as per bleeding)
6) carefully push the pistons back in all the way. when you refitted the hose to the lever, some air will have become trapped, and this will have resulted in a small air bubble sitting inside the hose. by pushing the pistons back in, this will push the air bubble up into the lever and you should see it appear in the fluid reservoir, and float to the top.
7) refit reservoir top cap. refit pads and wheels and pump lever to reset pistons. make sure the brakes are not spongy – hopefully you’ll know what they should feel like.
good luck 🙂