Files written on Windows, opened under Linux or UNIX, each line will have more characters like ^m, because Windows is different from *nix's newline character, so let's see how the file format differs.
To view file formats under Linux:
# file filename
# 20140304110001.csv:iso-8859 text//Not with ^m
# 20140304110002.csv:iso-8859 text, with CRLF line terminators//with ^m
Files processed under Windows have a CRLF line terminator.
There are several ways to handle this:
1. Input in the VI command line mode
:%s/^m$//g # Remove the ^m at the end of the line.
:%s/^m//g # Remove all the ^m.
:%s/^m/[ctrl-v]+[enter]/g # Replace ^m with a carriage return.
:%s/^m/\r/g # Replace ^m with a carriage return.
2. Use the SED command. Similar to the use of VI:
# sed-e ' s/^m/\n/g ' filename
3. Using commands
With the Dos2unix command, the generic *nix release version comes with this gadget, the Windows-*nix file conversion.
Format: Dos2unix filename
Convert multiple Files
Format: Dos2unix file1 file2 file3 ....
The original file will be modified when the file is converted, using the-K parameter, or the-n parameter can not change the file properties.
Format: dos2unix-n oldfile newfile//Create a new file to keep the source file intact
Format: dos2unix-k filename//Keep file timestamp unchanged
The same tool provides the *nix-windows file format Conversion command: Unix2dos, parameters with Dos2unix.
* Note: "^m", need to use CTRL + V + CTRL + M type, instead of the number 6 above the ^+ letter M.
Above is the Linux processing file content in the ^m character of the introduction, if the ^m character affects your reading, you want to remove it, just follow the method described in this article, you can easily remove the ^m character.
Open on Linux or UNIX, each line will have more characters like ^m