Walt Disney has agreed to buy the bulk of 21st Century Fox's business for $52.4bn (£39bn), in a deal both companies said position them to compete in the rapidly changing media industry.