This stackoverflow question has an answer to replace newlines with sed, using the format sed \':a;N;$!ba;s/\\n/ /g\'.
This works, but not for special characters like
This should work with both LF or CR-LF line endings:
LF
CR-LF
sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' file