Train services will be disrupted on two routes in South Wales in mid-July to allow Network Rail to carry out essential engineering works.