The pill was bitter, but network and studio execs knew they had to swallow it in order to survive this year’s upfronts.

After years of refusing to find a remedy to what ailed the business, the industry finally appeared ready to clamp down on out-of-control costs. But it didn’t come without side effects.

“The business is brutal,” one tenpercenter said after the weeklong dust had settled Thursday.

The network-studio give-and-take wasn’t easy in some cases — leading to the demise of shows such as NBC’s “My Name Is Earl” and both “Without a Trace” and “The Unit” at CBS. CBS’ production arm and the Peacock got into a money scuffle over drama “Medium” that wound up sending the Patricia Arquette starrer to CBS’ Friday night lineup after four seasons on NBC.

The Big Four even wound up squeezing their own sister studios in some cases as they turned over cushions to find every last dime. ABC opted to ax ABC Studios’ “Samantha Who?” after the show couldn’t find a way to trim $500,000 an episode, and Fox and sister 20th Century Fox TV wound up in a rough negotiation over the fifth season of “Bones.”

“There’s going to be pushes on both sides so we can make these viable businesses,” ABC Entertainment topper Steve McPherson said this week. “Cost containment is alive and well … There’s no question we’ve taken tens of millions of dollars out of budgets.”

At the same time, network and studio execs said the give-and-take wasn’t as rough as it could have been — and indeed has been in the past. There appears to be a much wider recognition among everyone, even reps, that this is the new TV economic reality.

“The health and well-being of the industry is in all of our best interest,” said Warner Bros. TV prexy Peter Roth. “One part of the equation, gouging the other, is not” in anyone’s interest, he said.

Angela Bromstad, prexy of primetime entertainment for NBC and Universal Media Studios, added: “I hope that people are open to working in lower budgets. It’s just gotten financially unsustainable. This isn’t anything we didn’t see coming (but) it takes a lot to turn the town around.”

One exec says the cost-cutting went far beyond just slashing license fees and trimming budgets. Deals took longer to make because studios looked at everything in order to find ways to trim costs: profit participations, backends, advance against profits and more.

“The pressure’s been on the entire industry the last couple of years,” said Sony TV programming/production co-prexy Jamie Erlicht. “And there was an increased pressure this year. At the same time, you evaluate each show and figure out how much you can trim while still protecting the quality.”

CBS TV Studios topper David Stapf said the economy made it necessary to look at making some changes now, which they did with producers.

“You look at these shows line item by line item and find ways to cut costs without taking it off the screen,” he said.

The economic tussles this season didn’t all fall the networks’ way. When “Two and a Half Men” came up for renewal at CBS earlier this year, it was Warner Bros. TV that had more leverage.

By last week, it was the bubble shows — with the notable exception of “Ghost Whisperer” and “Bones,” both of which hit their magic five-year mark — that felt the brunt of the economic squeeze.

“There were some license fee decreases, and the studios said, ‘OK, we’ll find a similar decrease in the production cost,’ ” one exec said. “There was a resetting this year of what the networks and studios can do in the case of their bubble shows. This is not a bad thing. Successful hit shows should be appropriately compensated, while you can try to find meaningful ways to maintain the life of these bubble shows.”

With the economy in recession and the advertising marketplace still shaky, congloms are also looking at ways to spread the risk around. That’s partly why Sony was willing to give up an ownership stake in hot new comedy “Community” to NBC without much fuss.

At ABC, the net managed to mitigate risk by throwing open the doors and picking up series from several outside suppliers.

ABC downplayed the fact that so many of its new shows came from outside Disney, arguing that it simply picked up the best shows. And indeed, 20th’s new ABC laffer “Modern Family” got the best marks of the week thanks to the Alphabet’s decision to run the pilot in its entirety during the net’s upfront presentation.

“We’re feeling incredibly fortunate that we’ve got three of the most hotly anticipated new shows with ‘Glee,’ ‘Modern Family’ and ‘Cleveland,'” said 20th Century Fox TV chairman Gary Newman.

The intense focus on costs was a complicating factor this year, but 20th has for several seasons sought to be selective about the projects it takes on and in balancing its slate with big-budget swings and some more modestly budgeted entries.

“We’re thinking about how can we manage a portfolio of some shows that are lower risk and some that are higher risk,” 20th chairman Dana Walden said. “You look at where the networks are putting your series and make educated decisions on that. Clearly, we’re going to be aggressive about a show that has been given the post-‘House’ time period,” she said, referring to the studio’s sophomore drama “Lie to Me,” the Tim Roth starrer that is getting a big push from Fox next season.

ABC also bet big on Warner Bros. TV, picking up five new shows from the studio, including Bruckheimer drama “The Forgotten,” the fantasy dramedy “Eastwick” and laffers starring Patricia Heaton (“The Middle”) and Kelsey Grammer (“Hank”).

With the networks now more closely aligned than ever with their sister studios (except Fox, where Peter Chernin’s departure actually separated them further), Warner Bros. execs said they launched a strategy to be every network’s secondary supplier.

It clearly worked, as Warner Bros. TV got 12 new shows on the air in both fall and midseason. The studio produces 26 series in total, with shows at every network.

“It exceeded our expectations,” Roth said. “In a world where there are five fewer hours’ worth of shelf space on one network, and a greater predilection for inhouse consideration at the others, to be an indie studio and have 12 new series gives us great satisfaction in terms of sales.”

Fox also showed a willingness to go outside of its sister studio, picking up two Warner Bros. TV shows in midseason, as well as a fall laffer from Sony.

“This is a hit-driven business, and to self-deal while trying to find those hits is a big mistake,” said Sony TV programming/production co-prexy Zack Van Amburg.

The networks are covering their bases, however, while doing those types of deals in order to avoid facing tough renegotiations down the road.

The Alphabet net, for example, is believed to be asking for six- to eight-year license deals (as opposed to the old four-year standard). That should cover the life of these new shows, as few make it further than that — and if they do, they’re usually past their peak.

Beyond ABC and Fox, however, the nets pretty much stuck with their sister studio fare. NBC had Sony’s “Community” (which it now co-produces as well) but otherwise picked up only Universal shows. And all of CBS’ new fall series came from CBS TV Studios. At the CW, the netlet picked up shows only from Warner Bros. TV and CBS TV Studios.

Whether or not they’re on the road to recovery, TV honchos expressed an unusual bit of optimism by the end of the week.

Some were simply pleased to have made it through the week without any major blow-ups. The indie studios were pleased to get some shows on the networks. Every net had at least one new show that people were buzzing about — be it “Glee,” “Modern Family,” “Community,” “Melrose Place” or “Undercover Boss.”

Maybe it’s the reports that show an encouraging uptick in the advertising marketplace. And maybe, after being beaten up by a strike-fueled work stoppage, followed by a crippling recession, the execs are confident that they’ve made enough changes to weather whatever ails the biz.

“It’s as challenging a year as I can ever remember,” said one studio chief. “Arguably the most challenging. But I feel better.”

(Cynthia Littleton contributed to this report.)