dos2unix AND unix2dos : Converting between DOS and UNIX

Here r the 2 lines from a DOS file, atul, viewed on a unix system with the vi editor :

Line 1^M
Line 2^M


$ od -bc atul  
{ this command is used to check the CR-LF in file }

There is a ^M ( ctrl – m ) representing the CR sequence at the end of each line. An octal dump confirm this :
The CR-LF combination is represention by the octal value 015 -012 and the escape sequesnce \r\n. Conversion of this file to UNIX is just a simple matter of removing the \r. This is often done automatically when downloading a UNIX file from windows machine using ftp, but sometimes u have to do it yourself.

$ dos2unix atul.dos atul 
$ unix2dos atul.dos atul

* unix2dos inserts CR before every LF, and thus increase the file size by the no of line in the file.
* You can use dos2unix to delete the ^M char that occurs at the end of every line in the file typescript.
* If u view the unix file atul on windows using notepad but without performing the conversion then you’ll see a single line : Line 1Line 2. In fact, whenever you see a single line on a windows machine that should have been multiple line.
* Never perform this conversion on a binary file.

 
 

njoy the simplicity…….
©Victimizeit

Advertisements

About victimizeit
This is Atul.. working for IBM as a DataStage Developer. I may not be an expert on any particular DataStgae technology, but I'm sure I do know a few things about DB2, AIX, Unix, Windows, and DataBase. In this blog, I'll give out some tips on these subjects. If you find them useful, great, I'll be happy. Thanks for stopping by !!

What is your opinion ?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: