Dealing with Newline Issues on Text Files: Examples and Reference

Dealing with Newline Issues on Text Files: Examples and Reference

Last updated:
Table of Contents
Style Name Character Hexcode Decimal
Windows-styleCR LF\r\nOxD 0xA13 10
Unix-styleLF\n0xA10

Windows-style to unix-style newline

In other words, convert \r\n to \n.

Use sed:

$ sed ':a;N;$!ba;s/\r\n/\n/g' windows-newlines.txt > out.txt

Replace CR LF with LF

See above: Windows-style to unix-style newline

Replace \r\n with \n

See above: Windows-style to unix-style newline

Open file in hexadecimal mode

Use hexedit. You can also edit the file directly.

hexdit-edit-hexcode Using hexedit to view and edit a text file.
Hex codes in orange area and the
equivalent text in blue


References

  • Vim Hexcode table http://vimdoc.sourceforge.net/htmldoc/digraph.html#digraph-table