UPDATE 1-Gates Foundation divests in medical companies

* Foundation sells stakes in large medical firms

* Firms include Wyeth, Abbott, Eli Lilly, Pfizer, J&J

* Foundation bought energy, McDonald’s shares

NEW YORK, Aug 14 (Reuters) - The Bill & Melinda Gates Foundation, the charitable foundation of Microsoft Corp MSFT.O founder Bill Gates, sold off its stakes in a number of pharmaceutical companies, according to a regulatory filing.

During the quarter that ended on June 30, the foundation sold 15 million shares of Schering Plough SGP.N, 3.7 million shares of Wyeth WYE.N, 3.5 million shares of Abbott Laboratories ABT.N, 3.4 million shares of Pfizer PFE.N, 2.5 million shares of Johnson & Johnson JNJ.N and 938,000 shares of Eli Lilly LLY.N.

The Foundation also bought new shares in the energy sector, purchasing stakes in Cabot Oil & Gas Corp COG.N, CSX CSX.N, and XTO Energy Inc XTO.N. It also increased its stake in McDonald's MCD.N to 6.9 million shares from 6.4 million shares.

The value of the trust’s total stock holdings was down to $7.49 billion from $8.48 billion at the end of the the previous quarter. (Reporting by Steve Eder; Editing Bernard Orr)