Changing mktemp calls and some two sed calls to make it work with BSD coreutils (and still GNU coreutils valid)