Remove ^M CR (carriage return) from output/file


^M is a carriage return (CR), which can be specified as \r for tr or within $'…'. \n specifies a line feed (LF), which is ^J. A Unix line ending is LF, and a Windows line separator is the two-character sequence CR-LF, so Windows text files viewed under a Unix system such as Linux or macOS look like they have ^M at the end of each line except on the last line which is missing its final newline.

You can remove carriage returns from a file with tr with

tr -d '\r' <somefile.txt >somefile.txt.new && mv somefile.txt.new somefile.txt
 
SOMEOUTPUT | tr -d '\r'


Source: https://unix.stackexchange.com/questions/326120/way-to-remove-newline-m-from-variables-only-not-from-file