Wednesday, January 30, 2008

Simple UNIX/DOS Newline Conversion

I LOVE the command-line! I'm a keyboard & command-line kind of guy. Even in Windows, I'll use as many keyboard shortcuts as possible.

I'm currently working on an older Oracle 10g server that's not working. Despite the fact that it's running on a Windows 2000 Server, Oracle's log files are formatted with Unix newlines instead of Windows/DOS CR+LF.

Some quick Google magic yielded a page from Wikipedia, and the following command:

UNIX to DOS (Run on a DOS/Windows Machine):
TYPE unix_file | FIND "" /V > dos_file

DOS to UNIX (Run on a Unix/Linux Machine):
tr -d '\r' < dos_file > unix_file
or
tr '\r' '\n' < dos_file > unix_file

NOTE:
MOST *nix systems have the dos2unix and unix2dos utilities, but the above commands should work on 99% of *nix systems without any additional packages.

NOTE:
The first *nix command works if dos_file uses the standard CR+LF, the second works if dos_file uses only CRs.

Just replace unix_file and dos_file with the appropriate filenames.

The best part: This command should work on ANY Microsoft OS, from DOS to Server 2003, without any special software or utilities.

I hope you find it as useful as I have already!

No comments: