CVS Caremark (CVS) narrowly beat the Street on Tuesday with an 18% bump in second-quarter profits thanks in part to rival Walgreen’s (WAG) recent stumbles, prompting the drug store operator to boost its full-year financial targets.

Shares of the No. 2 drug-store chain jumped almost 3% in the wake of the earnings beat.

Walgreen said it earned $966 million, or 75 cents a share, last quarter, compared with a profit of $816 million, or 60 cents a share, a year earlier. Excluding one-time items, it earned 81 cents a share, besting consensus calls from analysts by a penny.

However, revenue jumped 16.3% to $30.71 billion, barely missing the Street’s view of $30.96 billion.

CVS pleased shareholders by raising its guidance, projecting non-GAAP EPS of $3.32 to $3.38, up from $3.23 to $3.33 previously. The midpoint of the new range, $3.35, would beat estimates by two pennies. Management also backed its call for 2012 free cash flow of $4.6 billion to $4.9 billion.

CVS, which is also a pharmacy benefits manager, said second-quarter results were boosted by a 28.2% leap in pharmacy services revenue to $18.4 billion.

CVS alluded to the trouble at Walgreen, which only recently resolved a dispute with pharmacy benefits manager Express Scripts (ESRX). The lack of a deal caused Walgreen’s sales to slump, apparently to the benefit of rival CVS.

Second-quarter retail pharmacy sales rose 5.6%, CVS said.

“Our retail business continued to benefit from the market disruption caused by the contractual impasse between two of our competitors, and we have detailed plans in place to maximize retention following their mid-September resolution,” CEO Larry Merlo said in a statement.

Shares of Woonsocket, R.I.-based CVS jumped 2.9% to $46.20 ahead of Tuesday’s open, putting them on pace to extend their 2012 rally of 10%.

Follow Matt Egan on Twitter @MattMEgan5