Comcast posted a higher-than-expected quarterly profit on Wednesday as an increase in internet and phone customers offset weakness at its NBC Universal unit, which had a flop with the movie "Battleship'' and lower advertising revenue at the NBC broadcast network.

The largest U.S. cable TV operator, whose shares rose more than 2 percent, added 156,000 high-speed internet subscribers and 158,000 phone customers during the second quarter. Analysts at Canaccord Genuity had expected Comcast to add just 97,000 Internet subscribers and 143,000 phone customers. Comcast's video subscriber base continued to shrink, though at a slower rate than in recent quarters. It lost 176,000 subscribers during the period.

"They were in line with our expectations of strength at cable, but weak trends at NBCU,'' said Brean, Murray, Carret & Co. analyst Todd Mitchell.

Revenue at NBC Universal dipped 0.8 percent to $5.50 billion, and operating cash flow dropped 15.4 percent.

At the struggling NBC broadcast business, revenue fell 9 percent from a year earlier, when it received advance licensing fees from Netflix for TV shows like "Law & Order.'' The Universal Studios business had negative cash flow of $83 million, which it blamed on the expensive flop "Battleship.''

Revenue from Comcast's cable networks, which include Bravo, CNBC and MSNBC, rose 3.6 percent to $2.25 billion. Second-quarter net income rose to $1.35 billion, or 50 cents a share, from $1.02 billion, or 37 cents a share, a year earlier.

Analysts had on average expected a profit of 48 cents a share, according to Thomson Reuters I/B/E/S.

Revenue rose by 6.1 percent to $15.21 billion. Shares of Comcast rose in trading before the market opened.

Comcast is the majority owner of NBC Universal, the parent company of CNBC and