Linux Text Format conversion

Source: Internet
Author: User

The Dos2unix command is used to convert a DOS-formatted text file into Unix (Dos/mac to UNIX text, format Converter).
Dos text file line break is \ r \ n, which means that 16 binary is 0D 0 A, and Unix text file newline character is \ n, expressed as 16 binary is 0 a. DOS format text files on Linux with a lower version of VI Open Line end will show ^m, and many commands can not handle the file in this format, resulting in the two format files to convert each other requirements, corresponding to the UNIX format text file into a DOS format is the Unix2dos command.
Use Cat-v to view nonprinting characters in a file

Grammar:

dos2unix [-hkqV] [-c convmode] [-o file ...] [-n infile outfile ...]

Options:

-K: Keep the date of the output file unchanged
-Q: Quiet mode without prompting for any warning messages
-V: View version
-C: Conversion mode, Mode: ASCII, 7bit, ISO, Mac, default is: ASCII
-O: Writing to the source file
-N: Writing to a new file

Instance

Convert single or multiple files

The simplest use is to Dos2unix directly to a file or multiple files

Dos2unix file1 file2 file3 ...

Batch conversion of files in directory

Linux itself provides both the Dos2unix and Unix2dos commands for converting Windows and Linux files,
However, Dos2unix and unix2dos themselves do not provide recursive options, which are bulk modifications, so they can be implemented using the Xargs command. The purpose of the Xargs command is to convert the argument list to small pieces to pass to other commands.

Suppose the file that needs to be converted is in the same directory as Public/components

Find public/components/-name "*" | Xargs Dos2unix

Advantages: Batch conversion, small workload. Bulk conversions with pipe and xargs, this method enables bulk operations of other commands (such as bulk deletion, etc.)

Linux Text Format conversion

Related Article

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.