The conversion method of the newline character of Windows file format and the newline character of Linux file under Linux system

■The difference between the
newline character of the Windows file format and the newline character of the Linux file The newline character dao:
1. The newline character in windows is \r\n, the corresponding ASCII code value (carriage return: \r=0x0d (13) return , Newline character\n=0x0a (10) newline)

  1. The newline character under linux/unix is ​​\n, the corresponding ASCII code value (newline character: \n=0x0a (10) newline)

■How to convert the newline character of Windows file format and the newline character of Linux file under linux:
1.unix2dos and dos2unix command
unix2dos: the newline character of Linux file format is converted to the newline character of Windows file format
dos2unix: the newline character of Windows file format Convert newline characters in Linux file format

2.sed command
sed -i's/\r//' filename> newfilename # Newline of Windows file format is converted to newline of Linux file format
sed -i's/\n/\r\n/' filename> newfilename # The newline character of Linux file format is converted to the newline character of Windows file format

3.Vim editor
command mode input: set fileformat=unix Windows file format newline character converted to Linux file format newline character can be saved in
command mode input: set fileformat=dos Linux file format newline character is converted to Windows file format newline Just save

Guess you like

Origin blog.51cto.com/14801055/2550918