Fortunately, quite a few tools are available to correct for this predictable type of distortion. I use clens, a command-line utility distributed with panotools, with the lens profiles that come with PTlens, a windows alternative to clens (you can find the database in panotools or here).
The top image above is a straight grid, as shot. You can see the curves that should be straight. The bottom image shows the automatic correction with clens, with the lens profile from PTlens.
clens is run like this:
clens -p profile.txt -s nona -l "Nikkor 18-200mm f/3.5-5.6 G ED-IF AF-S VR DX" image.jpg
If it run like this:
clens -p profile.txt -s nona --Lenses image.jpg
it outputs a list of possible lenses, according to the make of the camera and the focal length.
The correction is not perfect, since the Nikkor 18-200mm shows a more complicated (higher order) type of distortion that clens cannot correct for.