Filing a patent application costs around $180-$280 [1], not including the other Patent Office fees for Examination/Maintenance. Add onto that the legal fees for marking up the claims, charged out in the $XXX/hr range and you are looking at a few thousand easily.
A quick search turned up a 2011 American Intellectual Property Law Association survey suggesting a median cost of $10k [2].
Having in house legal team to take care of it may reduce the costs but Patent Office fees still make it at least a grand to get one. If the community can chip in a few hours to crush the patent then I would think it is time well spent.
Keep in mind that this is the costs for filing in one country. Each country where the invention needs to be protected needs its own filing, though this would generally be cheaper since much of the work (patent attorney fees) is already done when filing the first one. I have heard that big companies end up something half-a-million dollars for pursuing, what they consider worthy inventions, in all significant economies.
It costs the companies quite a bit, and a reasonably knowledgable person about 10-15 minutes to find prior art that, once discovered by someone at the USPTO, can help to fast-track a denial. In any case, you're at least helping to make sure that none of the ridiculous claims get through (these are common in patents, just to see if they can get away with it since they're already spending the money)
The cost is much higher than the filing fee. You should usually plan to spend about $20k to hire a patent attorney to help get a patent filed. If you are doing this yourself you can keep the cost much lower, and try to do all of the work yourself, but a company usually spends tens of thousands of dollars getting a patent filed.
At Boston University they have an office of about 5 people that evaluates university generated IP to see if it is worth patenting and if their market research doesn't show that it is worth $50k over the next few years they won't bother.