Egypt edge past Sudan to finish second in Group D and qualify for the last 16 of the Africa Cup of Nations.