We may safely assume $a=0$ since translation will not influence the integral in any ways. We want to prove that $\oint_{C}\frac{f(z)}{z}dz=2\pi if(0)$. Consider $z=re^{i\theta}$ we have $$\int_{|r|=R}\frac{f(re^{i\theta})}{re^{i\theta}}(dre^{i\theta}+re^{i\theta}id\theta)=\int_{|r|=R}\frac{f(re^{i\theta})}{r}dr+if(re^{i\theta})d\theta$$
We cannot apply Green's theorem directly because it assumes the area is simply connected. But we can calculate the integral directly via taking limit $R\rightarrow 0$. This can be done by noticing that since $r=R$ the left term actually vanishes; Thus we are left with $$\oint_{|r|=R}if(Re^{i\theta})d\theta=i\int^{2\pi}_{\theta=0}f(Re^{i\theta})d\theta$$
Taking the limit of this integral when $R\rightarrow 0$ should give you $2\pi if(0)$.
This small trivial calculation is associated with Poincare's lemma and DeRham Cohomology. You may venture to read some reference books if you are interested.
I wrote this post to make all of the minutia clear. The big picture is more important, though. See Mike's answer for that.
The general idea is this: we can define a holomorphic function whose real part looks just like the desired integrand on the real line, and we have some strong tools for integrating holomorphic functions, so maybe we can use information about this holomorphic function's integral to deduce information about our original integral.
In this case, we see that the real part of $f(z)=\frac{{1}-e^{iz}}{z^2}$ is precisely $\frac{1-\cos{x}}{x^2}$ if $z=x$ is real. That's why we consider $f(z)$. Its real part looks just like the function that we want to integrate. So we note that $$\int_{-\infty}^{\infty} \frac{{1}-e^{iz}}{z^2} \,dz = \int_{-\infty}^\infty \frac{1-(\cos{x}+i\sin{x})}{x^2} \,dx = \int_{-\infty}^{\infty} \frac{1-\cos{x}}{x^2} \,dx + i \int_{-\infty}^{\infty} \frac{-\sin{x}}{x^2} \,dx.$$ So, in particular, we have: $$\Re (\int_{-\infty}^{\infty} f(z) \,dz) = \int_{-\infty}^{\infty} \Re(f(z)) \,dz = \int_{-\infty}^{\infty} \frac{1-\cos{x}}{x^2} \,dx =2\int_{0}^{\infty} \frac{1-\cos{x}}{x^2} \,dx .$$ This means that if we can just figure out what $\int_{-\infty}^{\infty} f(z)$ is, then we can just take its real part, and that must be twice the integral you want to evaluate.
To figure out what $\int_{-\infty}^{\infty} f(z)$ is, we'd like to use the strength of Cauchy's theorem. Cauchy's theorem says that if we integrate over the given igloo, we've got to get zero, no matter what $R$ and $\epsilon$ are. We choose the igloo because we have to avoid the "problem" point at 0, where $f$ isn't holomorphic, and because we need a closed loop for Cauchy. We'll recover the integral on the real line from $-\infty$ to $\infty$ as we let $R$ get huge and $\epsilon$ get small.
As you note, from Cauchy's theorem, we get: $$\int_{-R}^{-\epsilon}\frac{1-e^{ix}}{x^2}dx + \int_{\gamma_{\epsilon}^+}\frac{1-e^{iz}}{z^2}dz + \int_{\epsilon}^R\frac{1-e^{ix}}{x^2}dx + \int_{\gamma_R^+}\frac{1-e^{iz}}{z^2}dz = 0.$$ Rearranging, this means that $$\int_{-R}^{-\epsilon}\frac{1-e^{ix}}{x^2}dx + \int_{\epsilon}^R\frac{1-e^{ix}}{x^2}dx = - \int_{\gamma_{\epsilon}^+}\frac{1-e^{iz}}{z^2}dz - \int_{\gamma_R^+}\frac{1-e^{iz}}{z^2}dz. \quad\quad (*)$$ Now, as we let $R$ and $\epsilon$ do their thing, the left side of this equation is going to tend to $\int_{-\infty}^{\infty} f(z) dz$. So we just need to figure out what the right side is doing. To do this, we'll consider what happens as we vary our diagram, taking $R$ to be really big first and then taking $\epsilon$ to be small. Since the above equalities didn't depend on our choices of $R$ and $\epsilon$, varying the diagram with big $R$ or small $\epsilon$ won't cause any problems.
As $R$ runs off to infinity, we have: $$\left|\int_{\gamma_R^+}\frac{1-e^{iz}}{z^2}dz\right| \le \int_{\gamma_R^+} \left|\frac{1-e^{iz}}{z^2}\right||dz| \le \int_{\gamma_R^+} \frac{2}{R^2} |dz| = \pi R \frac{2}{R^2} = \frac{2\pi}{R} \rightarrow 0,$$ so the $\int_{\gamma_R^+}\frac{1-e^{iz}}{z^2}$ term on the right hand side of $(*)$ goes to zero in the limit. So, letting $R$ go to infinity in $(*)$, we get $$\int_{-\infty}^{-\epsilon}\frac{1-e^{ix}}{x^2}dx + \int_{\epsilon}^\infty\frac{1-e^{ix}}{x^2}dx = - \int_{\gamma_{\epsilon}^+}\frac{1-e^{iz}}{z^2}dz, \quad\quad\quad (**)$$ which is just a rephrasing of the equality you asked about.
And now we just need to know what happens to the right side of this equation as $\epsilon$ gets small.
For this, we'll see what happens if we just take the power series representation for the $e^{iz}$ term in $f$ about zero. We have:
$$f(z) = \frac{1-e^{iz}}{z^2} = \frac{1 - \sum_{n=0}^\infty\frac{(iz)^n}{n!}}{z^2} = -\frac{\sum_{n=1}^\infty \frac{(iz)^n}{n!}}{z^2} = -\frac{iz}{z^2} +\sum_{n=2}^\infty \frac{(iz)^{n-2}}{n!}.$$
Let $E(z) = \sum_{n=2}^\infty \frac{(iz)^{n-2}}{n!}$ (the second term on the right hand side above). Notice that if $\epsilon<1$, then on $\gamma_{\epsilon^+}$, we have $$|E(z)| \le \sum_{n=2}^\infty \frac{|iz|^{n-2}}{n!} \le \sum_{n=2}^\infty \frac{1}{n!} \le e,$$ so $E(z)$ stays bounded as $\epsilon$ shrinks, and we see that if $\epsilon<1$, $$\left| \int_{\gamma_{\epsilon^+}} E(z) dz\right| \le \int_{\gamma_{\epsilon^+}} |E(z)| |dz| \le \int_{\gamma_{\epsilon^+}} e |dz| = \pi \epsilon e \rightarrow 0 \text{ as }\epsilon \rightarrow 0.$$
Thus, \begin{align*}\lim_{\epsilon \rightarrow 0^+} \int_{\gamma_{\epsilon^+}} f(z) dz &= \lim_{\epsilon \rightarrow 0^+} \int_{\gamma_{\epsilon^+}} -\frac{iz}{z^2} dz + \lim_{\epsilon \rightarrow 0^+} \int_{\gamma_{\epsilon^+}} E(z) dz\\ &= \lim_{\epsilon \rightarrow 0^+} \int_{\gamma_{\epsilon^+}} - \frac{i}{z} dz + 0\\ &= \lim_{\epsilon \rightarrow 0^+} -i \int_\pi^0 i dz\\ &= -\pi.\end{align*}
Combining with $(**)$ and letting $\epsilon$ go to zero, we finally have: $$\int_{-\infty}^\infty f(z) dz = \pi.$$ Taking the real parts of both sides gives $$\int_{-\infty}^\infty \Re f(z) dz = 2 \int_0^\infty \frac{1-\cos{x}}{x^2} dx = \Re\pi = \pi.$$
So $\int_0^\infty \frac{1-\cos{x}}{x^2} dx = \frac {\pi}{2}$.
Best Answer
To use Cauchy's theorem, you need to consider the integral in the complex plane. In doing that, you need to carefully consider the contour itself. Really, what you are doing is evaluating an integral
$$\oint_C dz \,\left (\frac{1}{ck-z} + \frac{1}{c k+z}\right )e^{-i \tau z}$$
where $C$ is a semicircular contour with deformations about the poles on the real axis. Let's consider the case $\tau \lt 0$ first. In this case, we use a semicircle of radius $R$ in the upper half plane. Then we get that the contour integral is
$$\int_{-R}^{-c k-\epsilon} d\omega\, \left (\frac{1}{ck-\omega} + \frac{1}{c k+\omega}\right )e^{-i \tau \omega} + i \epsilon \int_{\pi}^0 d\phi \, e^{i \phi}\, \left (\frac{1}{2 ck-\epsilon e^{i \phi}} + \frac{1}{\epsilon e^{i \phi}}\right ) e^{-i \tau (-c k+\epsilon e^{i \phi})} + \\ \int_{-c k+\epsilon}^{c k - \epsilon} d\omega\, \left (\frac{1}{ck-\omega} + \frac{1}{c k+\omega}\right )e^{-i \tau \omega}+ i \epsilon \int_{\pi}^0 d\phi \, e^{i \phi}\, \left (\frac{1}{2 ck+\epsilon e^{i \phi}} - \frac{1}{\epsilon e^{i \phi}}\right ) e^{-i \tau (c k+\epsilon e^{i \phi})}\\+ \int_{c k+\epsilon}^R d\omega\, \left (\frac{1}{ck-\omega} + \frac{1}{c k+\omega}\right )e^{-i \tau \omega} + i R \int_0^{\pi} d\theta \, e^{i \theta} \, \left (\frac{1}{ck-R e^{i \theta}} + \frac{1}{ck+R e^{i \theta}}\right ) e^{-i \tau R e^{i \theta}} $$
We consider the limits as $\epsilon \to 0$ and $R \to \infty$. The first, third, and fifth integrals combine to form the Cauchy principal value of the original integral (which is really the value you seek). The sixth integral is bounded by
$$\frac12 \int_0^{\pi} d\theta \, e^{R \tau \sin{\theta}} \le \int_0^{\pi/2} d\theta \, e^{2 R \tau \theta/\pi}\le \frac{\pi}{2 R (-\tau)}$$
(Recall that $\tau \lt 0$.) Thus, the sixth integral vanishes as $R \to \infty$. The second and fourth integrals have nonzero contributions that are easily evaluated as $\epsilon \to 0$.
By Cauchy's theorem, the contour integral is zero because there are no poles inside the contour $C$. Therefore
$$PV \int_{-\infty}^{\infty} d\omega\, \left (\frac{1}{ck-\omega} + \frac{1}{c k+\omega}\right )e^{-i \tau \omega} = i \pi \left (e^{i c k \tau} - e^{-i c k \tau} \right ) \quad (\tau \lt 0)$$
Now consider the case $\tau \gt 0$. Note that if we use the same contour as above, the sixth integral will not vanish and indeed does not converge. Therefore, we use another contour $C'$ which is a deformed semicircle in the lower half plane. To exclude the poles on the real axis from the interior of $C'$, we deform below the real axis at these poles. Thus, the contour integral in this case becomes
$$\int_{-R}^{-c k-\epsilon} d\omega\, \left (\frac{1}{ck-\omega} + \frac{1}{c k+\omega}\right )e^{-i \tau \omega} + i \epsilon \int_{\pi}^{2 \pi} d\phi \, e^{i \phi}\, \left (\frac{1}{2 ck-\epsilon e^{i \phi}} + \frac{1}{\epsilon e^{i \phi}}\right ) e^{-i \tau (-c k+\epsilon e^{i \phi})} + \\ \int_{-c k+\epsilon}^{c k - \epsilon} d\omega\, \left (\frac{1}{ck-\omega} + \frac{1}{c k+\omega}\right )e^{-i \tau \omega}+ i \epsilon \int_{\pi}^{2 \pi} d\phi \, e^{i \phi}\, \left (\frac{1}{2 ck+\epsilon e^{i \phi}} - \frac{1}{\epsilon e^{i \phi}}\right ) e^{-i \tau (c k+\epsilon e^{i \phi})}\\+ \int_{c k+\epsilon}^R d\omega\, \left (\frac{1}{ck-\omega} + \frac{1}{c k+\omega}\right )e^{-i \tau \omega} + i R \int_{2 \pi}^{\pi} d\theta \, e^{i \theta} \, \left (\frac{1}{ck-R e^{i \theta}} + \frac{1}{ck+R e^{i \theta}}\right ) e^{-i \tau R e^{i \theta}} $$
Now, note that the sixth integral vanishes for $\tau \gt 0$ because $\sin{\theta} \lt 0$ over the integration interval. Also note how the limits of integration have also changed for the second and fourth integrals, to reflect the change in direction of integration. Going through the same motions as above, therefore, we find that
$$PV \int_{-\infty}^{\infty} d\omega\, \left (\frac{1}{ck-\omega} + \frac{1}{c k+\omega}\right )e^{-i \tau \omega} = -i \pi \left (e^{i c k \tau} - e^{-i c k \tau} \right ) \quad (\tau \gt 0)$$
as I think you expected.