Question: $$x^2\left(\frac{dy}{dx}\right)+2xy=x^2-1$$

Here where I got with this:

$x\cdot\frac{dy}{dx} +2y = x-\frac{1}{x}$

$-2y=x\cdot\frac{dy}{dx} + \frac{1}{x} -x$

Then integrate:

$-y^2+C = \int x\cdot dy+\ln(x)-\frac{1}{2}x^2$

Now I am left with that final integral above, which I am in need of help to solve. Thanks

Answer: 
By product rule we have $\frac d {dx} (x^{2}y)=x^{2}-1$ so $x^{2}y=x^{3}/3-x+C$. Divide by $x^{2}$.
You can re-write the ODE as
$$y'+\frac{2}{x}y=\frac{x.^2-1}{x^2}$$
The integrating factor or this ODE is $I=e^{\int (2/x)dx}=e^{\ln x^2}=x^2$
So $$y=x^{-2}\int (x^2-1) dx+Cx^{-2}$$