How to evaluate this improper integral $\int_{0}^{\infty}\frac{1-x}{1-x^{n}}\,\mathrm dx$? 
$\def\d{\mathrm{d}}$How to evaluate this improper integral? 
  $$\int_{0}^{\infty}\frac{1-x}{1-x^{n}}\,\d x.$$

What I tried is a substitution i.e $x^{n}=t$, but then things got complicated, and I'm stuck.

We are going to evaluate the integral
$I:=\displaystyle \int_{0}^{\infty} \frac{1-x}{1-x^{n}} d x \tag*{} $
by the theorem
$ \displaystyle \sum_{k=-\infty}^{\infty} \frac{1}{k+z}=\pi \cot (\pi z), \textrm{ where } z\notin Z.\tag*{} $
We first split the integral into $2$ integrals
$ \displaystyle \int_{0}^{\infty} \frac{1-x}{1-x^{n}} d x=\int_{0}^{1} \frac{1-x}{1-x^{n}} d x+\int_{1}^{\infty} \frac{1-x}{1-x^{n}} d x \tag*{}$
Transforming the latter integral by the inverse substitution $ x\mapsto \frac{1}{x} $, we have
$$\displaystyle  \int_{1}^{\infty} \frac{1-x}{1-x^{n}} d x=\int_{0}^{1} \frac{x^{n-3}-x^{n-2}}{1-x^{n}} d x \tag*{} $$
Putting back yields
$$ \begin{aligned}\displaystyle  I&=\int_{0}^{1} \frac{1-x+x^{n-3}-x^{n-2}}{1-x^{n}} d x\\\displaystyle  &=\int_{0}^{1}\left[\left(1-x+x^{n-3}-x^{n-2}\right) \sum_{k=0}^{\infty} x^{n k}\right] d x\\ \displaystyle & =\sum_{k=0}^{\infty} \int_{0}^{1}\left[x^{n k}-x^{n k+1}+x^{n(k+1)-3}-x^{n(k+1)-2}\right] d x\\\displaystyle  & =\sum_{k=0}^{\infty}\left(\frac{1}{n k+1}-\frac{1}{n k+2}+\frac{1}{n(k+1)-2}-\frac{1}{n(k+1)-1}\right)\\\displaystyle & =\sum_{k=0}^{\infty}\left[\frac{1}{n k+1}-\frac{1}{n(k+1)-1}\right]+\sum_{k=0}^{\infty}\left[\frac{1}{n(k+1)-2}-\frac{1}{n k+2}\right]\\ \displaystyle & =\frac{1}{n}\left[\sum_{k=0}^{\infty} \frac{1}{k+\frac{1}{n}}+\sum_{k=-1}^{-\infty} \frac{1}{k+\frac{1}{n}}\right]+\frac{1}{n}\left(\sum_{k=1}^{\infty} \frac{1}{k-\frac{2}{n}}+\sum_{k=0}^{-\infty} \frac{1}{k-\frac{2}{n}}\right)\\\displaystyle & =\frac{1}{n}\left(\sum_{k=-\infty}^{\infty} \frac{1}{k+\frac{1}{n}}+\sum_{k=-\infty}^{\infty} \frac{1}{k-\frac{2}{n}}\right) \end{aligned}$$
By the Theorem
$\displaystyle  \sum_{k=-\infty}^{\infty} \frac{1}{k+z}=\pi \cot (\pi z), \tag*{} $
where $ z\notin Z.$
We can now conclude that
$\displaystyle \boxed{ I =\frac{1}{n}\left[\pi \cot \left(\frac{\pi}{n}\right)+\pi \cot \left(\frac{-2 \pi}{n}\right)\right]=\frac{\pi}{n}\left[\cot \left(\frac{\pi}{n}\right)-\cot \left(\frac{2 \pi}{n}\right)\right] =\frac{\pi}{n} \csc \frac{2 \pi}{n}} \tag*{} $
