Pages

Thursday, October 31, 2013

Convert DOS/MAC files to Unix format

Recently I came across file conversion issue in UNIX system. I have written a shell script in windows (i.e. via eclipse) once I completed, copied to designation server and I tried to run the same file.

But, surprisingly I got bad descriptor errors. I don’t know what the error was.  Developed script was fine no issues with syntax and logics. Later when I looked the contents of the file; I found out some of the system specific characters are in same file.


To overcome this kind file conversion issue, there is a UNIX command called “dos2unix” which is converting your dos/mac written file into UNIX format by removing those system characters.

Detailed explanation of  "dos2unix" command given below;

dos2unix - DOS/MAC to UNIX text file format converter

SYNOPSYS
       dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...]

       Options:

       [-hkqV] [--help] [--keepdate] [--quiet] [--version]

DESCRIPTION
       This manual page documents dos2unix, the program that converts plain text files in DOS/MAC format to UNIX format.

OPTIONS

       The following options are available:

       -h --help
              Print online help.

       -k --keepdate
              Keep the date stamp of output file same as input file.

       -q --quiet
              Quiet mode. Suppress all warning and messages.

       -V --version
              Prints version information.

       -c --convmode convmode
              Sets conversion mode. Where convmode is one of: ASCII, 7bit, ISO, Mac with ASCII being the default.  Simulates dos2unix under SunOS.

       -o --oldfile file ...
              Old file mode. Convert the file and write output to it. The program default to run in this mode. Wildcard names may be used.

       -n --newfile infile outfile ...
              New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be used or
              you WILL lost your files.

Example :

dos2unix filename.sh

No comments:

Post a Comment