Edit in JSFiddle

function FixData() {
    var ctrl = document.querySelector('#txtData');
    var txt = ctrl.value;
    
    txt = txt.replace(/[\r\n+]/g, " ");
    txt = txt.replace(/\s\s+/g, " ");
    
    ctrl.value = txt;
}
<textarea id="txtData" cols="70" rows="10"></textarea><br />
<input type="button" onclick="FixData()" value="Fix the flippin' Machine Key" />