dos2unix

Windows/MAC to UNIX text file format converter.

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

Key
   -c --convmode convmode
                    Set 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 defaults 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 lose your files.

   -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     Print version information.

dos2unix converts plain text files in DOS/MAC format to UNIX format.

Later versions of dos2unix have additional options to add/remove Byte Order Marks (BOM) and handle alternate code pages.

An alternative method using sed

sed -i -e 's/\r//g' file

Examples

Get input from stdin and write output to stdout:

dos2unix

Convert demo.txt and and save to the same file:

dos2unix demo.txt
or
dos2unix -o demo.txt

Convert and replace demo.txt while keeping the original date stamp:

dos2unix -k demo.txt
dos2unix -k -o demo.txt

Convert input.txt and and send output to output.txt:

dos2unix -n input.txt output.txt

Convert input.txt in ASCII conversion mode:

dos2unix -c ascii -n input.txt output.txt

Convert input.txt in ISO conversion mode:

dos2unix -c iso -n input.txt output.txt

Convert input.txt from Mac to Unix ascii format:

dos2unix -c mac -n input.txt output.txt

Convert input.txt and write to output.txt, keeping the date stamp of the original file:

dos2unix -k -n input.txt output.txt

Convert and replace demo.txt, also convert input.txt and write to output.txt:

dos2unix demo.txt -n input.txt output.txt
or
dos2unix -o demo.txt -n input.txt output.txt

“There is nothing noble in being superior to your fellow man; true nobility is being superior to your former self” ~ Ernest Hemingway

Related Linux commands

unix2dos - UNIX to Windows text file format converter.
dos2unix - man page


 
Copyright © 1999-2024 SS64.com
Some rights reserved