How do you get that last expression from the definition of RMS value on the line above?

Compute the mean square first (which is what is under the square root sign in the definition of RMS value).

You do the integral by splitting it into well behaved pieces (that looks like three pieces to me)

CB