Convert the line endings from DOS to UNIX format

CR = Carriage Return
LF = Line Feed

Betriebssystem Zeichensatz Abkürzung Code Hex Code Dezimal Escape-Sequenz
Unix, Linux, Android, Mac OS X, AmigaOS, BSD ASCII LF 0A 10 \n
Windows, DOS, OS/2, CP/M, TOS (Atari) ASCII CR LF 0D 0A 13 10 \r\n
Mac OS bis Version 9, Apple II, C64 ASCII CR 0D 13 \r
AIX OS & OS/390 EBCDIC NEL 15 21 \025


NAME          sed - stream editor for filtering and transforming text
DESCRIPTION   Sed is a stream editor. A stream editor is used to perform
              basic text transformations on an input stream.
# replace every "\r" with ""
$ sed "s/\r//" infile >outfile

# add in every line-end (RegEx $) before \n the character \r
$ sed "s/$/\r/" infile >outfile

How to convert DOS/Windows newline to Unix newline in bash script?
sed Tutorium – Eine Einführung in sed
Useful one-line scripts for sed


NAME          tr - translate or delete characters
DESCRIPTION   Translate, squeeze, and/or delete characters
              from standard input, writing to standard output.
# delete every "\r"
tr -d \r <infile >outfile

Leave a Reply

Your email address will not be published. Required fields are marked *