How do I differentiate the many varieties of brake/shifter cables?
You can easily buy shift (Compressionless/Index compatible) housing and brake (conventional helical) housing in bulk -- most bike shops buy it by the roll (of about 40-50 meters). Note most housing is shift only or brake only, and you should never use shift only housing for brakes (it will break). With non-index shifting though, you should be able to get acceptable performance with using brake housing for shifting. Expect to pay 1-2 USD per meter in bulk. 

Note that there are housings that are suitable for both index shift and brake, such as some made by Nokon (but these are expensive; about 50 dollars/ meter). 

Ferrules you can also buy in bulk -- you can easily buy them in little tubs of 100 or so for a few cents a piece.

Brake and shift cables will need to be bought individually (in the sense that you can't buy a roll of them and cut them yourself; you can obviously buy big lots of them at a discount). This is because you need to have the cable ends attached so that they can hook into the shifter/brake lever, and this needs to be done at manufacturing time. There are different varieties for different shifter and brake types. This is partially due to manufacturers, and also the different styles of the shifters/brakes. It's not a big deal -- no different really than needing a few different parts for working on a Honda than on a Ford, but you just need to know which ones you need. 

These days the shift+brake cable types are relatively standard (since Shimano/SRAM are the vast majority of drivetrains out there): Most non-flat bar bikes (e.g. drop bar road bikes) will use the same brake cable (A) in the figure below, and most flat bar bikes (many hybrids/ mountain bikes) will use (C) for their brakes. And most bikes will use (D) for their shifting. 

The people who need (B,E) would know a priori that they need them (since they spent a lot of money on their Campagnolo drivetrains).

Note that many Shimano/SRAM cables are sold double ended -- one has the road end on it, the other has the mountain end. You just cut off the end you don't need and use it as you would if it only came with the proper end.



(Figure from Bikeman)

For some classical shifters/brake levers (old Suntour, for example), the original cables used different ends than whats on the market now (e.g. a shift cable with a  ball end with diameter of the similar radius to (D) rather than (D)). In these cases, it doesn't hurt to do a google search to see what people are running for those cables. Or, take it to the shop -- they should have a copy of Sutherland's handbook which will tell them what the right cable is for practically anything. In some cases, you may end up filing another cable end down anyway (which isn't ideal, but sometimes it has to be done). Back in the old days, there were a bunch of manufacturers of stuff and things weren't as standardized as they are now (since Shimano has overrun the market, and SRAM is Shimano compatible for a lot of things). 



A few remaining points: 


With older (pre index shifting) setups it doesn't make much difference with quality of cables/housings (particularly for shifting) and carefulness of installation. But you might see a perceptible difference if you install cables/housings poorly on modern (index shifting) setups or use poor quality stuff.  
The retailer you buy your stuff from can make a huge difference in price (also, what kind of bikes you have, which determines how much housing and stuff you need). I think I spent about 10 USD a bike last time I did this.
It probably doesn't make sense to buy bulk rolls of housing -- it's going to take forever to get through it for most people in a non-shop setting, and it takes up space. You don't need to replace them that often, and for one or two bikes, 50 m may be enough to last you close to the end of your riding life.  




Further reading: Sheldon Brown's always good. This page from Bikeman in the comments is useful too.