A store log outside of the headquarters of Fred's Pharmacy Memphis, Tennessee.

Shares of Fred's surged 82 percent Monday after it announced it will sell some pharmacy files to Walgreens for at least $165 million.

Walgreens will purchase files and related pharmacy inventory of 185 Fred's stores across 10 Southeast states. As part of the deal, Walgreens will pay $165 million, subject to adjustment, plus an amount equal to the value of related pharmacy inventory.

The companies expect to start transferring files in the fourth quarter and complete the process in the first quarter of next year. Once that is complete, Fred's will continue to operate about 162 pharmacies across nearly 600 stores.

"With this agreement, we have taken a major step towards achieving one of our main goals of eliminating our debt balance," said Fred's interim CEO and CFO Joe Anto.

Fred's patients will receive letters notifying them of the transfer.

"This agreement increases patient access to Walgreens pharmacies in the Southeastern U.S., and allows us to introduce more people to Walgreens trusted pharmacy services in these communities," said Walgreens President of Operations Richard Ashworth.

Walgreens shares rose nearly 1 percent Monday.