Inspiration & Genius – One and the Same

Convert DOS newlines CR-LF to Unix/Linux format

From http://www.cyberciti.biz/

Howto: UNIX or Linux convert DOS newlines CR-LF to Unix/Linux format

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

A. To convert 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.

UNIX/Linux Commands

* 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

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 newlines (CR/LF) to Unix format using sed command

If you are using BASH shell type the following command (press Ctrl-V then Ctrl-M to get pattern or special symbol)

$ sed 's/^M$//' input.txt > output.txt

Task: Convert UNIX to DOS format using sed command

Type the following command if you are using bash shell:

$ sed 's/$'"/`echo \\\r`/" input.txt > output.txt

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Genesis Framework

Genesis Framework for WordPress

Studiopress Themes

Scribble Theme - A Beautiful Frame For Your WordPress Website

Advertisements