Customer prescription records and pharmacy inventory at 24 Waldbaum's and Pathmarks on Long Island will be sold to CVS and Rite Aid as part of a deal worth more than $31 million.

Earlier this week, a federal bankruptcy judge in White Plains approved the pharmaceutical assets sale from 74 pharmacies owned by the Great Atlantic & Pacific Tea Co.

CVS will purchase the prescription records from 58 stores for $25 million and certain pharmacy inventory for up to $9.964 million. Rite Aid will purchase the prescription records of 16 stores for $6.387 million and other pharmacy inventory for up to $2.795 million, according to court documents filed last week.

StoryOver 4,000 LI A&P workers may lose jobsSee alsoWhat happened to your Waldbaum's, Pathmark storeSee alsoBest, worst supermarkets

As part of the deal, CVS is acquiring the pharmacy business of 21 A&P-owned locations on Long Island, CVS spokesman Mike DeAngelis said Wednesday.

Rite Aid is taking over pharmacy files from a Waldbaum's in Massapequa, and Pathmarks in Brentwood and Bethpage, company spokeswoman Kristin Kellum said Thursday.

CVS and Rite Aid will not operate the physical pharmacies at the A&P-owned stores.

advertisement | advertise on newsday

After the deals close, pharmacy customers whose records are sold, and who have filled prescriptions within the past six months, must be notified by mail that their prescription information has been purchased by CVS or Rite Aid.

Pharmacy records are expected to be handled in accordance with Health Insurance Portability and Accountability Act (HIPAA) privacy standards and other applicable laws, according to court records.

Separately, Walgreens announced this week it is buying Rite Aid for about $9.41 billion. The deal, which still needs regulatory approval, would combine the largest and third-largest drugstore chains in the United States, totaling nearly 18,000 stores around the world. CVS is buying pharmacy records and inventory of these Long Island locations:

Pathmark in Bay Shore

Waldbaum's in Deer ParkWaldbaum's in East Meadow

Pathmark in East Rockaway

Waldbaum's in East Setauket

Waldbaum's in Greenlawn

advertisement | advertise on newsday

Pathmark in Holbrook

Waldbaum's in Huntington

Pathmark in Islip

Waldbaum's in Jericho

Waldbaum's in Lindenhurst

advertisement | advertise on newsday

Pathmark in Massapequa

Waldbaum's in Melville

Waldbaum's in Merrick

Pathmark in New Hyde Park

Pathmark in North Babylon

Pathmark in Patchogue

Pathmark in Port Jefferson

Waldbaum's in Selden

Pathmark in Shirley

Pathmark in West Babylon

Rite Aid is buying pharmacy records and inventory of these Long Island locations:

Waldbaum's in Massapequa

Pathmark in Brentwood

Pathmark in Bethpage