Open on Linux or UNIX, each line will have more characters like ^m

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.