Railroad companies bounced back in the second quarter, thanks in part to a rare boost from coal.

Train operators have sought out growth in automotive and industrial shipments to offset weakness in coal at a time when utilities are widely choosing lower-priced natural gas. The prolonged winter created another headwind during the first three months of the year, dampening shipping volume and causing expenses to rise.

Analysts expected railroads to report better earnings in the latest period, and the frigid temperatures that plagued much of the country proved to be an added bonus as utilities moved to replenish their stockpiles of coal.

Norfolk Southern (NSC) said revenue generated by coal shipments jumped 7% compared to the same period a year ago, driven by a 3% improvement in volume. The company cited severe winter weather and higher natural gas prices that spurred coal demand from utilities.

In the first quarter, Norfolk Southern’s coal revenues were down 15% year-over-year. The company now expects utility coal volumes to remain positive in the second half.

Increased shipments of cars and construction materials also supported growth in Norfolk Southern’s revenue, fueling a 21% jump in second-quarter earnings.

CSX (CSX), which reported modest earnings growth of 1.5%, saw coal volume grow 6.5%. The Jacksonville, Fla.-based company also said the rise in domestic coal shipments can be attributed to stock replenishment by utilities.

Morgan Stanley analysts said downside risk in CSX’s stock primarily centers on coal, but those headwinds “are both fully understood and gradually easing,” they wrote in a research note to clients.

“Coal has been the biggest challenge for eastern rails in recent years and, while the headwinds will persist, they may be easing. In fact, CSX reported 24% growth in domestic utility coal tonnage in 2Q,” the analysts added. Eastern railroads include CSX and Norfolk Southern.

Goldman Sachs noted that coal uncertainties remain, with global competition depressing export prices. Softness on the export front could neutralize increased demand from domestic utilities, analysts at the investment bank wrote. Goldman Sachs maintained its “neutral” rating for CSX.

Strength in grain and car shipments offset fewer coal shipments at Kansas City Southern (KSU), the smallest of the “big four” railroads.

Union Pacific (UNP) said total revenue carloads, or volume, rose 8% in the second quarter, helped by a 1% increase for coal. Freight revenues and average revenue per car for coal were also up 1%.

Agricultural shipments led the way with a 16% gain, while industrial products and intermodal volume each improved 12%. Union Pacific, the largest publicly traded railroad company, booked an overall profit of $1.3 billion, up 17%.

Chief executive Jack Koraleski said Union Pacific will continue to monitor “the potential impact of weather on grain and coal.”

Goldman Sachs analysts expect Union Pacific to continue outperforming the rest of their transportation coverage amid volume growth that outpaces the overall market. Key risks to the stock include coal, which could contribute to weaker-than-expected traffic.

On Friday, shares of Union Pacific edged a penny lower to $101.76. The stock is up roughly 21% since the start of the year. CSX has gained 7.9% year-to-date, while Norfolk Southern has rallied 15.7%.

Follow Matthew Rocco on Twitter @MatthewRocco