Wild Pointer 程序员问答社区

HowTo Convert DOS Newlines to Unix/Linux Format

How do I convert DOS newlines CR/LF to Unix/Linux format?

To converts text files between DOS and Unix formats you need to use special utility called dos2unix. DOS text files traditionally have carriage return and line feed pairs as their newline characters while Unix text files have the line feed as their newline character.

1
标签:           

  1. Forec 查看完整答案
    0

    You can use the following tools:

    dos2unix (also known as fromdos) – converts text files from the DOS format to the Unix format unix2dos (also known as todos) – converts text files from the Unix format to the DOS format. sed – You can use sed command for same purpose tr command Perl one liner Task: Convert DOS file to UNIX format

    Type the following command to convert file called myfile.txt: $ dos2unix myfile.txt

    However above command will not make a backup of original file myfile.txt. To make a backup of original file. The original file is renamed with the original filename and a .bak extension. Type the following command: $ dos2unix -b myfile.txt

    Task: Convert UNIX file to DOS format

    Type the following command to convert file called myfile.txt: $ unix2dos myfile.txt $ unix2dos -b myfile.txt

    Task: Convert Dos TO Unix Using tr Command

    Type the following command:

    tr -d '\r' < input.file > output.file Task: Convert Dos TO Unix Using Perl One Liner

    Type the following command:

    perl -pi -e 's/\r\n/\n/g' input.file Task: Convert UNIX to DOS format using sed command

    Type the following command if you...

添加回答

你可以使用 MarkDown 语法编写回答。

你需要先登录并激活账号后才可以添加回答。