cp test -r  changed to cp -r test ...

in OSX arguments must be exactly after their commands.
Fixing OSX sed issues.

GUN/sed is different from OSX sed, this change uses OSX sed.