Originally Posted by

**FernandoRevilla** Another way: denote $\displaystyle I(\lambda)=\int_0^{+\infty}\frac{\cos \lambda x}{x^2}dx\;(\lambda >0)$ , then $\displaystyle I'(a)=-\int_0^{+\infty}\frac{\sin \lambda x}{x}dx$ . Using the substitution $\displaystyle t=\lambda x$ we get $\displaystyle I'(\lambda)=-\int_0^{+\infty}\frac{\sin t}{t}dt=-\frac{\pi}{2}$ (Dirichlet's integral) . So, $\displaystyle I(\lambda)=-\frac{\pi}{2}\lambda+C$ . For $\displaystyle \lambda =0$ we get $\displaystyle C=\int_0^{+\infty}\frac{dx}{x^2}$ .

Then,

$\displaystyle \int_0^{+\infty}\frac{\cos ax-\cos bx}{x^2}dx=-\frac{\pi}{2}a+C-\left(-\frac{\pi}{2}b+C\right)=\boxed{\frac{\pi (b-a)}{2}}$

**@fareastmovement**: Show your complete work by the method of residues (of course if you want) and we can check it.