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

An alternative method using tr:

tr -d '\15\32' < indosfile.txt> outunix.txt

An alternative method using awk:

awk '{ sub("\r$", ""); print }' indos.txt > outunix.txt

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 indos.txt and and send output to outunix.txt:

dos2unix -n indos.txt outunix.txt

Convert input.txt in ASCII conversion mode:

dos2unix -c ascii -n indos.txt outunix.txt

Convert input.txt in ISO conversion mode:

dos2unix -c iso -n indos.txt outunix.txt

Convert input.txt from Mac to Unix ascii format:

dos2unix -c mac -n inmac.txt outunix.txt

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

dos2unix -k -n indos.txt outunix.txt

Convert and replace demo.txt, also convert indos.txt and write to outunix.txt:

dos2unix demo.txt -n indos.txt outunix.txt
or
dos2unix -o demo.txt -n indos.txt outunix.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-2025 windevcluster.com
Some rights reserved