Use target encoding when replacing newlines with spaces
Cut newlines prior to recoding