Trim output before splitting lines to avoid blank entries, closes #1978