Using Gauss's law (differential form) on an infinite line of charge I just read about Gauss's law in differential form and how to compute divergence. I worked out the $1/r^2$ field and got zero as expected! I was very happy. Then I thought the infinite line of charge, which produces a $1/r$ field. So I wrote out my $E$ vector field: 
$\frac{x\hat i +y\hat j+z\hat k}{\sqrt{x^2+y^2+z^2}}*\frac{1}{\sqrt{x^2+y^2+z^2}}$, the first part being the direction and the second the $1/r$ part. I worked out the divergence to be $\frac{1}{x^2+y^2+z^2}$, but shouldn't it be zero because outside of the line of charge there is no other charge? 
I confirmed that my math was correct with Wolfram alpha. 
 A: Your expression for the electric field in Cartesian coordinates is incorrect. The field is not radial, it points away from the line of charge.
If we put the line of charge along the z-axis, then the E-field is
$$\vec{E} = \frac{x\vec{i} + y\vec{j}}{x^2 + y^2}$$
with some multiplicative constant involving the charge per unit length and $\epsilon_0$.
The divergence of this is zero unless $x=y=0$.
A: We need to be using cylindrical coordinates instead of the spherical coordinates you have implicitly used.
The field you have takes the form:
$$\vec E=\frac{\lambda}{2\pi r \epsilon_0} \hat e_r$$
Where we have used cylindrical coordinates.
The div in cylindrical coordinates is given by: 
$$\nabla \cdot (A_r \hat e _r+A_\theta \hat e_\theta +A_z \hat e_z) =\frac{1}{r} \frac{\partial r A_r }{\partial r}+\frac{1}{r}\frac{\partial A_\theta }{\partial \theta}+\frac{\partial  A_z}{\partial z} $$
In your case $A_r=\frac{\lambda}{2\pi r \epsilon_0} $ so we have:
$$\nabla \cdot \vec E=\frac{1}{r}\frac{\partial (r \frac{\lambda}{2\pi r \epsilon_0} )}{\partial r}$$
$$=\frac{1}{r}\frac{\partial (\frac{\lambda}{2\pi  \epsilon_0} )}{\partial r}=0$$
As required. Of course this does not hold for $r=0$ where you need to look at the Dirac delta function.
