Convert text file formats between Windows and Linux

Source: Internet
Author: User

Problem: text that can be normally wrapped in Linux will not be wrapped in windows.

 

When changing a line in windows, there are two characters: Carriage Return (/R) and line feed (/N ). But in Linux, there is only one line feed (/N)

You can use unix2dos and dos2unix commands to convert the format:

Parameters:

-K: The timestamp of the output file and input file remains unchanged.

-O default file mode. Convert the file and output it to file

-N new infile OUTFILE mode. Convert infile and output it to OUTFILE

 

 

1.Unix2dos

 

Assume that you use VI to create a text file and enter 123456

[Root @ centos test] #Ls-l a.txt

-RW-r -- 1 Root 7 Jan 7 21:31 a.txt

[Root @ centos test] #Hexdump-C a.txt

0000000 1 2 3 4 5 6/n

0000007

[Root @ centos test] #Unix2dos-N a.txt B .txt

Unix2dos: Converting file a.txt to file B .txt in DOS format...

[Root @ centos test] #Ls-l

Total 8

-RW-r -- 1 Root 7 Jan 7 21:31 a.txt

-RW ------- 1 Root 8 Jan 7 21:34 B .txt

[Root @ centos test] #Hexdump-C a.txt

0000000 1 2 3 4 5 6/n

0000007

[Root @ centos test] #Hexdump-C B .txt

0000000 1 2 3 4 5 6/R/n

0000008

B .txt is a converted DOS file.

 

2.Dos2unix

[Root @ centos test] #Dos2unix-N B .txt c.txt

Dos2unix: Converting file B .txt to file c.txt in UNIX format...

[Root @ centos test] #Ls-l

Total 12

-RW-r -- 1 Root 7 Jan 7 21:31 a.txt

-RW ------- 1 Root 8 Jan 7 21:34 B .txt

-RW ------- 1 Root 7 Jan 7 21:38 c.txt

[Root @ centos test] #Hexdump-C B .txt

0000000 1 2 3 4 5 6/R/n

0000008

[Root @ centos test] #Hexdump-C c.txt

0000000 1 2 3 4 5 6/n

0000007

C.txt is a converted UNIX text file.

 

 

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.