This is called shuffling. You can do it by grind then hold ollie+direction, then release and immediately hit grind, then do the opposite to shuffle back (hold ollie+direction, release grind). This can help preserve your balance meter during the duration of the shuffle. Rails that are close together or double sided are ideal. The middle stripe of the freeway on East LA is ideal, or most 2x4 wood railings.
Once you can do this you can start doing it faster, and the ollie hold becomes more of a ollie press+direction to quick grind, tap ollie+oppo direction to quick grind.
My xbox controller example goes like this: x+right->y, x+left->y, x+right->y....and so on.