That is why there are so many scrapped aircraft in graveyards, taken there, and stripped for parts over time, to repair other aircraft. Most are there because major service is due, and the cost of the 3 to 4 year long process is very high, often multiple times the actual value of the aircraft second hand, so they are flown there, parked and as parts are needed they are taken off, checked and recertified and then sold.
When you are down to pretty much only a fuselage and a lot of broomsticks and planks acting as placeholders for things like floors and panels they typically then bring over the tracked crawler with the large hydraulic shears on it and cut the remains into smaller parts, that can fit into a container, to go for smelting into new metal. Most of the 747's still flying are only doing so because there are still donors in graveyards that provide the needed certified parts. Interestingly the most expensive part and the most in demand, aside from engines and landing gear, are the original coffee machines, as they are no longer made in that exact model. Instrumentation there have been so many revisions made that often a plane in the yard will still have all the original instrumentation in there when it is nearly gutted if it is an early model. Upgraded avionics are however a very fast seller, often going out complete to upgrade another aircraft instead. Seats are also a fast mover, basically every part in the cabin is.