Derivative of $f(x)=|x|$
First of all, the formula only works for $x \neq 0$. The absolute value function is not differentiable at $0$.
The function
$$x \mapsto \begin{cases} 1 & x > 0\\ -1 & x < 0 \end{cases}$$
is the signum function on $\mathbb{R}^* = \mathbb{R}\setminus\{0\}$. I believe what you're asking is how you go from the piecewise definition above to the expression $\frac{|x|}{x}$. The reverse problem (showing that $\frac{|x|}{x}$ simplifies to the piecewise definition above) is easier. To do that, you can use the piecewise definition of the absolute value on $\mathbb{R}^*$; namely,
$$|x| = \begin{cases} x & x > 0\\ -x & x < 0. \end{cases}$$
The question still remains, how do I go from the piecewise definition of the signum function on $\mathbb{R}^*$ to the expression $\frac{|x|}{x}$? Well, let's think about what the piecewise definition says. It says that if $x$ is positive, the value of the function is $1$, and if $x$ is negative, the value of the function is $-1$. What function does this? Well, the function $x \mapsto x$ gives the right signs, but not the right magnitude. How can I get the magnitude to be $1$? Well, you can just divide by the current magnitude which is given by $|x|$. That is, if $x \neq 0$, then $\frac{x}{|x|}$ has magnitude $1$, and because $|x| > 0$, we haven't changed the sign. Therefore, this expression agrees with the piecewise definition above.
Note 1: We started with $x \mapsto x$ as this gives the correct sign, but we could have used any other function $f$ on $\mathbb{R}^*$ which satisfies $f(x) > 0$ for $x > 0$ and $f(x) < 0$ for $x < 0$. That is, if $f$ is such a function
$$\frac{f(x)}{|f(x)|} = \begin{cases} 1 & x > 0\\ -1 & x < 0. \end{cases}$$
Note 2: Let $\frac{f(x)}{|f(x)|}$ be an expression which is equivalent to the piecewise definition. For $x > 0$,
$$\frac{f(x)}{|f(x)|} = 1 = \frac{1}{1} = \frac{1}{\frac{f(x)}{|f(x)|}} = \frac{|f(x)|}{f(x)},$$
and for $x < 0$,
$$\frac{f(x)}{|f(x)|} = -1 = \frac{1}{-1} = \frac{1}{\frac{f(x)}{|f(x)|}} = \frac{|f(x)|}{f(x)}.$$
So $\frac{|f(x)|}{f(x)} = \frac{f(x)}{|f(x)|}$. Therefore, for any function $f$ satisfying $f(x) > 0$ for $x > 0$ and $f(x) < 0$ for $x < 0$, both $\frac{|f(x)|}{f(x)}$ and $\frac{f(x)}{|f(x)|}$ are equal to the piecewise expression of the signum function on $\mathbb{R}^*$. In particular, both $\frac{x}{|x|}$ and $\frac{|x|}{x}$ are equal to the signum function on $\mathbb{R}^*$.
Note 3: Another way to see that $\frac{x}{|x|}$ is an expression for the derivative of $|x|$ for $x \neq 0$ (and hence, so is $\frac{|x|}{x}$ by Note 2) is to use the definition $|x| = \sqrt{x^2}$. For $x \neq 0$, $h(x) = x^2$ is differentiable with derivative $h'(x) = 2x$, and $g(x) = \sqrt{x}$ is differentiable at $h(x) \neq 0$ with derivative $g'(h(x)) = \frac{1}{2}(h(x))^{-\frac{1}{2}}$. So by the chain rule
$$\frac{d}{dx} |x| = \frac{d}{dx}\sqrt{x^2} = \frac{d}{dx}g(h(x)) = g'(h(x))h'(x) = \frac{1}{2}(h(x))^{-\frac{1}{2}}2x = \frac{x}{\sqrt{h(x)}} = \frac{x}{\sqrt{x^2}} = \frac{x}{|x|}.$$
Just note that $$\frac{|x|}{x}$$ is equal to $1$ when $x$ is greater than $0$, and less than $1$ when $x$ is less than $0$. The derivative of the function $f(x)=x$ always has a value of $1$, as does the function $f(x)=-x$, thus $|x|/x$ is a suitable expression. Also note that the function is not differentiable at $x=0$, therefore the domain of $d/dx |x|$ is the reals besides $0$.
Edit. Let $|x|=\sqrt{x^2}$, thus $$\frac{d}{dx}\sqrt{x^2}=\frac{1}{2\sqrt{x^2}}\cdot2x$$ $$=\frac{x}{\sqrt{x^2}}$$ $$=\frac{x}{|x|}.$$ Now, it is known that $$\frac{x}{|x|}=\frac{|x|}{x}$$ $$\therefore x^2=|x|^2$$ which is true for $x\in R$. Thus, if $f(x)=|x|$, then $$f'(x)=\frac{|x|}{x} \space x\neq0.$$