Section 129B. The sentence of any prisoner in any correctional institution of the commonwealth or in any house of correction or jail, who was held in custody awaiting trial shall be reduced by the number of days spent by him in confinement prior to such sentence and while awaiting trial, unless the court in imposing such sentence had already deducted therefrom the time during which such prisoner had been confined while awaiting trial.